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

Add a mechanism for generating random LogicValues #232

Closed
mkorbel1 opened this issue Dec 20, 2022 · 3 comments · Fixed by #362
Closed

Add a mechanism for generating random LogicValues #232

mkorbel1 opened this issue Dec 20, 2022 · 3 comments · Fixed by #362
Assignees
Labels
enhancement New feature or request

Comments

@mkorbel1
Copy link
Contributor

Motivation

LogicValue is a useful type since it supports arbitrary width in an efficient representation. For testing purposes, it might be desirable to generate a random value on a bus of arbitrary width. The built-in Dart randomization only randomizes up to 2^32, which means users have to invent their own little code snippets to generate random numbers bigger than 32 bits.

Desired solution

A way to generate large random numbers, especially for LogicValue.

One nice option might be to add an extension on Random.

It might be nice to support both valid values or a mix of valid and invalid values.

It might be nice to support random BigInts as well.

Alternatives considered

No response

Additional details

No response

@mkorbel1 mkorbel1 added the enhancement New feature or request label Dec 20, 2022
@quekyj
Copy link
Contributor

quekyj commented Jan 3, 2023

@mkorbel1 Let me work on this next.

@quekyj
Copy link
Contributor

quekyj commented May 3, 2023

Random().nextLogicValue(10);

@quekyj
Copy link
Contributor

quekyj commented May 3, 2023

arguments:

  • width, maximum value, invalid bits (x and z) - true/false (bool)

generate 32 bits at a time, start with nextInt(). nextInt() will only generate 32 bits.

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

Successfully merging a pull request may close this issue.

2 participants