I recently read somewhere that values with less significant bits tend to be less random than with more significant bits, could someone explain this better? If you can pass me some paper that talks about this and about random numbers I would be very grateful, as long as it doesn't have a lot of complex math
-
There's some discussion of this in [question 13.16](http://c-faq.com/lib/randrange.html) of the [C FAQ list](http://c-faq.com). – Steve Summit Sep 21 '21 at 23:36
-
1Burn the book, or ignore it. – wildplasser Sep 22 '21 at 00:03
-
2@wildplasser: Why? It sounds like the source was discussing old low-quality random number generators and was doing so correctly. Why should people not be advised that some random number generators are bad and have low “randomness” in their low bits? – Eric Postpischil Sep 22 '21 at 00:19
2 Answers
There are two things at play here.
First is the algorithm. Whether particular bits of a pseudorandom number generator's (PRNG) output are "weaker" than others, depends on the algorithm. For example, many PRNGs that rely on linear recurrences (such as many linear congruential generators) will produce outputs whose bits have shorter periods the less significant they are. This tends to be at its worst when the so-called "modulus" is a power of 2 (or more generally, a power of a prime number). The first paper cited below reviews the theory of linear congruential generators, and the second paper shows a particular phenomenon of such generators.
Steele and Vigna, Computationally easy, spectrally good multipliers for congruential pseudorandom number generators, 2020/2021.
Durst, Using linear congruential generators for parallel random number generation, 1989 Winter Simulation Conference.
Second is the nature of
rand
(andsrand
) in the C language, which is true regardless of the algorithm used by a particularrand
implementation. Perhaps the most serious ofrand
's weaknesses is the fact thatrand
doesn't guarantee a particular distribution the pseudorandom numbers must follow. For more information see: Why is the use of rand() considered bad?

- 32,158
- 14
- 82
- 96
-
The uniform distribution may not be specified explicitly in the C standard, but it's very clearly implied by history. – Nate Eldredge Sep 21 '21 at 23:40
This is a commentary on the often poor quality of random number generator used for the C library rand() function. The numbers it returns is supposed to be perfectly random--that is, if you asked for a million such numbers, you would not me able to find a pattern to predict the next one.
But if rand() uses a poor algorithm, it's possible to find patterns in the numbers it returns, and predict future numbers, or perhaps some bits of future numbers. In particular, the low-order bits of the returned numbers (that is, the bits representing 2^0, 2^1, 2^2, ...) are more predictable than the high-order bits (those representing 2^31, 2^30, ...). It might be possible to say, for example, that we don't know what the next number will be exactly, but there's a 60% chance its low bit is 1, rather than 50%.
The cure is simply to not use the built-in rand() function, but use a trusted library or algorithm to generate random numbers--and never "roll your own" (i.e., write your own RNG).

- 12,927
- 3
- 29
- 55
-
-
5That's a good one, but rarely the best. There are much faster algorithms with as big or bigger a period for things like games and Monte Carlo integration, and there are more secure algorithms for cryptography. – Lee Daniel Crocker Sep 21 '21 at 23:35
-
The partial cure is to avoid using the low-order bits, as discussed in the [C FAQ list](http://c-faq.com/lib/randrange.html). – Steve Summit Sep 21 '21 at 23:35