Closed msmftc closed 2 years ago
I have a similar problem when trying to randomize in small sets, for example:
@vsc.randobj
class constraints(object):
def __init__(self):
self.key = vsc.rand_bit_t(8)
@vsc.constraint
def c(self):
self.key in vsc.rangelist(0, 255)
cr = constraints()
for i in range(1000):
# Get now random stimuli
cr.randomize()
assert cr.key == 255
The assertion never hits, I always get 255.
Hi @msmftc and @tmeissner, I've made a couple of improvements make better use of reachable-domain information when applying randomization (available in the 0.6.8 release). Thanks for providing the examples above. I've incorporated the examples you have above as random-distribution tests. I'll close this for now, but feel free to reopen if needed.
The random distribution is much better now, thank-you.
@mballance,
When I use
vsc.rangelist(vsc.rng(min, max))
to describe a range of contiguous integers inside a constraint, the distribution is extremely skewed for small ranges and somewhat skewed for large ranges. In constrast, if I explicitly list the integers (as invsc.rangelist(5, 6, 7, ... N)
) then the distribution is good.The example code below illustrates the issue. Property A is constrained using
vsc.rng(0, 19)
while property B is constrained with a list of integers from 0 to 19. Randomization skews A to always be 19, while B is well distributed.Property C shows that for longer ranges the skew is not as bad, but is still significant. C is constrained using
vsc.rng(0, 1999)
. Randomization skews C to nearly always be in the upper half of the range, [1000..1999].A partial solution could be for PyVSC to internally expand short vsc.rng ranges into explicit lists of integers.