Basically I want to generate random numbers that won’t ever repeat for a very long period (I don’t want to use a sequence) like for example the LCG that java uses:
synchronized protected int next(int bits) {
seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1);
return (int)(seed >>> (48 - bits));
}
As I understand the seed in this case will only repeat after 2^48 calls to next is this correct?
so it is my understand that if I did a method like:
synchronized protected long next() {
seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1);
return seed;
}
The seed value is guaranteed not to repeat before 2^48 calls?
Not for that LCG, since you are modding out by 2^48 each time you call it (and thus the period/state is at most 2^48 in length). If you want a better random number generator, you could try the Mersenne twister:
http://en.wikipedia.org/wiki/Mersenne_twister
The standard MT19937 has a period of 2^19937-1 (!!!) That should be more than you will ever need.