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

Random.natIn that is inclusive of upper value #170

Open
ceedubs opened this issue Aug 18, 2023 · 2 comments
Open

Random.natIn that is inclusive of upper value #170

ceedubs opened this issue Aug 18, 2023 · 2 comments

Comments

@ceedubs
Copy link
Contributor

ceedubs commented Aug 18, 2023

I would like to generate a Nat with an inclusive upper value of maxNat. Is there a straightforward way to do that currently? Since natIn lower upper is exclusive on upper, you can't do natIn lower maxNat. For cases other than maxNat, you could do natIn lower (increment upper), but this will overflow and give an error if upper is maxNat.

See also #169.

@pchiusano
Copy link
Member

@ceedubs you can use Random.nat to generate Nat in the full range 0 to maxNat, does that help?

@ceedubs
Copy link
Contributor Author

ceedubs commented Aug 18, 2023

@pchiusano yes, but it's a bit annoying. In my current use-case the upper bound is passed in as an argument to the function, so I'll have to check whether the upper bound is maxNat and use nat if it is and natIn if it is not. If the lower bound were also passed in as an argument I think that I'd still have the same trouble.

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