4 ms·
The calculation maps a random number R in range 0..255 to numbers 1..10 via R % 10 + 1 The problem is that 10 does not evenly divide 256, hence for large
by cygx 4y ago
The calculation maps a random number R in range 0..255 to numbers 1..10 via
R % 10 + 1
The problem is that 10 does not evenly divide 256, hence for large R, the mapping will be incomplete. Specifically,
250 => 1
251 => 2
252 => 3
253 => 4
254 => 5
255 => 6
with no more random numbers available to yield results 7, 8, 9 and 10.
- wdutch 4y agoThanks for the explanation!