stdlib
stdlib copied to clipboard
int.random behaviour
pub fn random(min: Int, max: Int) -> Int
- "min" and "max" can be used interchangeably, which is confusing to me. e.g. random(-1, 1) is the same as random(1, -1)
- 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.
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.
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?
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.