Question 13.18

I need a random true/false value, so I'm just taking rand() % 2, but it's alternating 0, 1, 0, 1, 0...


Poor pseudorandom number generators (such as the ones unfortunately supplied with some systems) are not very random in the low-order bits. Try using the higher-order bits: see question 13.16.

References: Knuth Sec. 3.2.1.1 pp. 12-14


Read sequentially: prev next up top


This page by Steve Summit // Copyright 1995 // mail feedback