Have you ever needed to generate a random number in code? whether it's for rolling a dice, or shuffling a set, this tweet thread is here for you! There's no reason that it should be easy or obvious, very experienced programmers repeat common mistakes. I did, before I learned ...
Wow! WHY?? Don't use doubles either! or ever use a floating-point scalar (even a bignum) if you want a uniform distribution of ints at the end. It won't be.
-
-
Dividing a number by the maximum is mathematical operation that by definition is uniform. That 32 bit floats don't have enough accuracy to store all possible results is an different issue. (Using fixed points would fix that, but could also be affected by your modulo problem.)
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.