SecureRandom with NativePRNG vs SHA1PRNG

TL;DR: Use new SecureRandom() when you’re not sure and let the system figure it out. Possibly use SecureRandom.getInstanceStrong() for long term key generation. Do not expect a random number generator to generate a specific output sequence within a runtime application, not even if you seed it yourself. With random number generators it is always hard … Read more

Do stateless random number generators exist?

A random number generator has a state — that’s actually a necessary feature. The next “random” number is a function of the previous number and the seed/state. The purists call them pseudo-random number generators. The numbers will pass statistical tests for randomness, but aren’t — actually — random. The sequence of random values is finite … Read more

Reversible pseudo-random sequence generator

I asked a very similar question at the tigsource forums. Hashing At least in games, a hash function could probably do what you want. You could do it like this class ReversibleRNG { int x; public: ReversibleRNG(int seed) : x(seed) {} int next(){return yourFavoriteHash(++x);} int prev(){return yourFavoriteHash(–x);} }; Reversible linear congruential generator (lcg) As multiple … Read more