Closed aneels3 closed 4 years ago
Hi @aneels3, Agreed, support for rand_mode makes sense and should be feasible. After a bit of investigation, I'm aware of one small user-interface difficulty. Because of the operator overloading that PyVSC provides that allows users to obtain the value of scalar fields directly, it's most likely that the user will need to switch to an explicit mode when changing the rand-mode of scalar fields. Something like the following:
with vsc.raw_mode():
it.a.rand_mode = False
I'm still looking at options to see if there is a better way to handle this. Thanks for the suggestion!
Best Regards, Matthew
Hi @aneels3,
I've completed support for rand_mode
on scalar fields. Support will be available in the 0.0.7 release. See the Constraints section for more information on how to use rand_mode
. You can also see a short example below:
@vsc.randobj
class my_cls(object):
def __init__(self):
self.a = vsc.rand_uint8_t()
self.b = vsc.rand_uint8_t()
# First, test that values vary
init_a = 0
init_b = 0
it = my_cls()
for i in range(20):
with it.randomize_with():
it.a != init_a
it.b != init_b
self.assertNotEqual(it.a, init_a)
self.assertNotEqual(it.b, init_b)
init_a = it.a
init_b = it.b
# Now, disable rand_mode for a
with vsc.raw_mode():
it.a.rand_mode = False
self.assertEqual(it.a.rand_mode, False)
self.assertEqual(it.b.rand_mode, True)
for i in range(20):
with it.randomize_with():
it.b != init_b
self.assertEqual(it.a, init_a)
self.assertNotEqual(it.b, init_b)
init_a = it.a
init_b = it.b
# Now, go back
with vsc.raw_mode():
it.a.rand_mode = True
self.assertEqual(it.a.rand_mode, True)
self.assertEqual(it.b.rand_mode, True)
for i in range(20):
with it.randomize_with():
it.a != init_a
it.b != init_b
self.assertNotEqual(it.a, init_a)
self.assertNotEqual(it.b, init_b)
init_a = it.a
init_b = it.b
Hi @mballance I can see that we have support for constraint_mode() for the current version release. Can we have support for the rand_mode() as well?
Thanks!