Search code examples
mathrandomjavalcg

why 48 bit seed in util Random class?


Why this class uses 48 bit seed in its linear congruence formula? I would have expected 32 or 64...

I know it takes higher order bits when asked for 32 bit values. But why only 16 more additional bits? Was it a "random" choice?


Solution

  • You need more bits of state than bits of output, because the nature of an LCG is such that the low-order bits of state are not very random at all. So if you want 32-bit outputs, you need more than 32 bits of state.

    Why use 48 rather than 64? Because 48 is enough, and you're designing this decades ago, so there are good reasons to want to avoid using any more resources than are strictly necessary.