3 ms·
How else do you generate an unbiased random number between 0 and 250? As far as I know, that's the standard algorithm.
by mistercow 13y ago
How else do you generate an unbiased random number between 0 and 250? As far as I know, that's the standard algorithm.
- jlgreco 13y agoMy concern is with why they are doing that in the first place. It is possible that I am missing something here, I haven't looked at their actual code, but it seems to me that this concern would have been entirely avoided if they went with 0-F instead of 0-9.
- mistercow 13y agoYes, I definitely agree with that, and I don't understand why they did it that way. Generating a float in the [0,1) range by producing decimal digits seems utterly perverse. The sane, naive, and correct way to do it is to generate an integer between 0 and 2^53 and then divide by 2^53.
- marshray 13y agoOr use an array of integers 0 <= n < 2^x. Some of the Javascript libraries involved are even using such a format.
- mischanix 13y agoPerhaps grab 5 bytes instead?