I want to generate a large amount of random data that is reproduced for a given key containing a list of numbers:
[a, b, c, d, e, ...]
It is the next good or reasonable way to get RNGs in a position to generate random data in such a way that for each n-tuple [a, b, c, ..., n] this data is not correlated with the output for "adjacent" n -tuples [a+1, b, c, ..., n] , [a, b+1, c, ..., n] , etc.
srand(a); srand(rand() * b); srand(rand() * c); ... srand(rand() * n);
I think this question boils down to the following: is rand_hash good hash function for a 2-tuple (a, b) ?
int rand_hash(int a, int b) { srand(a); srand(rand() * b); return rand(); }
NB: I do not want to mean that srand and rand are any specific RNG implementation. Assume for the sake of argument that we are using good Mersenne Twister code.
Change If this is not clear, by “reasonable hash function” I mean the following. In the limited case of a 2-tuple [a, b] , the output of rand_hash should be uniform in the range of int , and (as a rule) there should be no correlation between the magnitude of the change in a or b and the magnitude of the change in the return value.
Nick
source share