mciepluc / cocotb-coverage

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

randomize() function generates repeated values #37

Closed Divya2030 closed 4 years ago

Divya2030 commented 4 years ago

How to generate non repetitive values using randomize() function in crv???

mciepluc commented 4 years ago

@Divyanirankari I am not sure what do you mean. Do you mean to make sure variables are different? In that case you should define a constraint (e.g. for variables x and y):

add_constraint(lambda x, y: x != y)

Or you mean that each randomization should guarantee non-repetitive results? In that case you should define a set of already used values and define constraint which prevenrs from picking values from this set. Example for variable x:

class Foo(Randomized):
    __init__(self):
    self.used = []
    self.x = 0
    self.add_rand("x", range(100))

    def avoid_used(x):
        return x not in self.used

    self.add_constraint(avoid_used)
...
object = Foo()
object.randomize()
object.used.append(object.x)
Divya2030 commented 4 years ago

@mciepluc Thanks. i want each randomization should guarantee non-repetitive results.