mciepluc / cocotb-coverage

Functional Coverage and Constrained Randomization Extensions for Cocotb
BSD 2-Clause "Simplified" License
100 stars 15 forks source link

Suggest add_rand() creates attribute if it does not exist #60

Open jonpovey opened 2 years ago

jonpovey commented 2 years ago

I have been reading the documentation (and source) for Randomized and add_rand() It seems like add_rand() could create an attribute if it is not found in the object, and perhaps initialise it to the first element in the domain list. It seems like this would reduce boilerplate in common code where currently the examples require writing self.x = some_dummy_value before add_rand("x", ...)

mciepluc commented 2 years ago

Hi @jonpovey Not sure if I like it - you do not need to randomize an object to use it. I agree it is an additional code needed, but also readability is better. I don't like being too pythonic by reducing amount of code, paying the clarity price. I would agree to add this feature if there are more votes.