Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bitvector.random #31

Open
phanrahan opened this issue May 18, 2019 · 3 comments
Open

bitvector.random #31

phanrahan opened this issue May 18, 2019 · 3 comments

Comments

@phanrahan
Copy link
Collaborator

if I do Bits16 = BitVector[16]

I can't do Bits16.random() to get a random number. I seem to need to call BitVector.random(16).

Am I missing something? I am contantly generating number numbers for tests, so this would be a nice feature to have.

I am thinking it would also be good to create options for different distributions of random numbers. For example, SIntVector.random(width, sampler="stratified") which ensures that half the random numbers are positive and half are negative. Similarly for FPVector.

@cdonovick
Copy link
Collaborator

@phanrahan I agree it would make sense to make the random method a classmethod instead of a staticmethod (already the case FPVector).

I am not quite sure what it means to ensure half the random numbers are positive and half are negative on a method that returns a single number.

@phanrahan
Copy link
Collaborator Author

We could alternate generating positive and negative numbers. Just make sure for a small number of calls that we stratify the samples. Mostly, I want to create a framework for using better sampling methods.

@cdonovick
Copy link
Collaborator

@phanrahan I created an SMT based constrained random generator for fault. However, the constraints are on individual samples not over a set of samples.
https://github.com/leonardt/fault/blob/master/fault/random.py
https://github.com/leonardt/fault/blob/master/tests/test_constrained_random.py
For "stateful" constraints it make sense to change the api from

bv = BitVector.random(size)

to

for bv in BitVector.random_generator(size, sampler=sampler, num_samples=N):
   ...

or

for bv in sampler(size, N):
   ...

tagging @leonardt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants