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

int.random behaviour #512

Open
schurhammer opened this issue Nov 27, 2023 · 3 comments
Open

int.random behaviour #512

schurhammer opened this issue Nov 27, 2023 · 3 comments

Comments

@schurhammer
Copy link
Contributor

pub fn random(min: Int, max: Int) -> Int
  1. "min" and "max" can be used interchangeably, which is confusing to me. e.g. random(-1, 1) is the same as random(1, -1)
  2. the maximum value is excluded from output (i.e. not the max but the actually higher value)

I'm not sure if this behaviour is intended, but at least it needs to be documented.

@inoas
Copy link
Contributor

inoas commented Nov 28, 2023

I did implement the first verion and I think someone changed it later.

"min" and "max" can be used interchangeably, which is confusing to me. e.g. random(-1, 1) is the same as random(1, -1)

This was in the first version and might be gone because people complained about performance instead of rolling their own. AFAIR.

the maximum value is excluded from output (i.e. not the max but the actually higher value)

This is behaviour in the Erlang implementation and the JS implementation says it should be the case but it isn't so there is a small check in the JS implementation, or at least that was the case.

@giacomocavalieri
Copy link
Member

I think that #486 is addressing this issue; you can have a look at the documentation they added, I think it does a good job at explaining the behaviour of the random function
Would this solve the issue, @schurhammer?

@lpil
Copy link
Member

lpil commented Nov 29, 2023

Sorry I've not kept on top of this item of work. I'm unsure what is best here, and whether we should continue to do these checks for which of the two numbers is largest.

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

4 participants