| |
When random is not actually random enough
Using the modulo operator to randomly select from a set (e.g., `random_number % set_size`) does not preserve uniform distribution, causing some items to be selected more frequently than others. For example, using modulo 3 on a uniformly distributed random number from 0-9 results in the first choice being picked 40% of the time while the others are picked only 30% each. A correct approach requires a dedicated `random_between(l, h)` function that properly ensures each item has an equal probability of selection.
Read Full Article →
← More Tech news