Reputation:
I recently created a RNG LCG, the formula is:
newSeed = (131173 * actualSeed + 27) % 262144;
But I have a question, this RNG is used to introduce a single seed and then it will generate a sequence. But I, for other reasons, need to introduce a seed for each number that is governed by: n * x, n is any number and x is the x coordinate, with this I achieve that if n is a seed and I want to generate a random map , will always generate the same.
The problem is that doing this is the equivalent of:
y = (131173 * x + 27) % 262144
and this gives numbers that grow and return to zero when 131173 * x + 27 is equal to 262144(m), this does not give the illusion of being random, I have tried that when introducing the seed, the seed is modified so that the resulting numbers are with an aspect more random, but I don't know if this works well, I need advice.
I have tried that when the seed is entered, the seed is:
x * x
, and after
(x * x) | n(seed)
, this does give me a more random look, but I don't know if it's the best way to solve my problem.
Upvotes: 0
Views: 241
Reputation: 413
The usual start for PRNG seed is using a time reference so that you will know that on the next round, it will start from a new seed.
A classic for the standard library srand
is in fact
srand (time(NULL));
Upvotes: 0