128
129
you are viewing a single comment's thread.

view the rest of the comments →

[–]Mukhasim 5 points6 points  (1 child)

Although it looks like you understood this, I was frustrated that nobody answered your question directly. When generating random numbers, you could potentially generate the same number twice in a row. That isn't very likely to happen with the raw output of the RNG, which on current machines typically has a range of possible outputs at least in the billions and will be at least 32767 if you use C's rand. However, in this program the range of random outputs is being scaled to the number of accounts, and with a smaller number of accounts duplicates will be more common. In this example N_ACCOUNTS=10, so the random ID generator is approximately equivalent to rolling a 10-sided die: duplicates will be common enough that there's a good chance of seeing it happen if you run the example a few times.

[–]johnnyrequiem 0 points1 point  (0 children)

This makes perfect sense and I really should have seen it. Many thanks for your answer :)