What’s the benefit of seeding a random number generator with only prime numbers?

Well one blink at the implementation would show you that he CAN’T have any reason for that claim at all. Why? Because that’s how the set seed function looks like:

synchronized public void setSeed(long seed) {
    seed = (seed ^ multiplier) & mask;
    this.seed.set(seed);
    haveNextNextGaussian = false;
}

And that’s exactly what’s called from the constructor. So even if you give it a prime, it won’t use it anyhow, so if at all you’d have to use a seed s where (s^ multiplier) & mask results in a prime 😉

Java uses a usual linear congruency method, i.e.:

x_n+1 = (a * x_n + c) mod m with 2 <= a < m; 0 <= c < m.

Since you want to get a maximal periode, c and m have to be relatively prime and a few other quite obscure limitations, plus a few tips how to get a practically useful version. Knuth obviously covers that in detail in part2 😉

But anyhow, the seed doesn’t influence the qualities of the generator at all. Even if the implementation would be using a Lehmer generator, it would obviously make sure that N is prime (otherwise the algorithm is practically useless; and not uniformly distributed if all random values would have to be coprime to a non prime N I wager) which makes the point moot

Leave a Comment