For example:
If rprng(seed,index)
is my function, then for any pair of (seed,index)
, I should always get the same value for a given (seed,index)
.
For example:
rprng(4,2) = 17
rprng(4,5) = 21
rprng(4,2) = 17
For example:
If rprng(seed,index)
is my function, then for any pair of (seed,index)
, I should always get the same value for a given (seed,index)
.
For example:
rprng(4,2) = 17
rprng(4,5) = 21
rprng(4,2) = 17
A simple idea is to use a PRNG that is so thorough that the values generated by seed
, seed+1
, seed+2
... are acceptably random. E.g.:
#include <random>
unsigned prng(unsigned seed, unsigned index)
{
thread_local std::mt19937 engine; // or a different engine
engine.seed(seed + index);
return engine();
}
Also check this thread: https://mathoverflow.net/questions/104915/pseudo-random-algorithm-allowing-o1-computation-of-nth-element
Use srand(seed) and all uses of myval=rand() that follow will be pseudo random. I often use this method as it is the easiest way of getting the same values from any given seed.
int rprng(int seed, int index){
srand(seed);
while(index-- >0)
rand();
return rand();
}