Which of these things, excactly? That Math just floats around in the global scope? Or that that destructuring assignment works? Or that the author chose to abstract around Math.random(). That has come very handy for me when testing.
- Posts
- 52
- Comments
- 1004
- Joined
- 2 yr. ago
- Posts
- 52
- Comments
- 1004
- Joined
- 2 yr. ago
I think
irandshould floor instead of round. First, when you want to generate a random number between 0 and 6 it’s often useful to exclude the 6. (See also https://www.cs.utexas.edu/~EWD/transcriptions/EWD08xx/EWD831.html).Second,
irand(0, 6)has a higher chance of rolling a 1 than a 0 because the capture area for 1 is [.5, 1.5), while the capture area for 0 is only [0, .5)Also if you had chosen any other variable names, it wouldn’t have taken me 5 minutes to figure out what these things do.
And one more, if you had swapped the input parameters, and defaulted to
n=0, you could call the use case “random number up to 6” with justrand(6)instead ofrand(0, 6).None of that matters in a private project, but… it just itched to point these things out.