Using wyhash64 to mix numbers into prngs?
smcallis opened this issue · comments
I noticed this comment here that wyhash64 can be used to generate deterministic random numbers that pass PractRand. Is there any recommendation on a good way to do that? Should I just pick a seed for B and a counter for A?
yes. you can fix one parameter as seed and use another one as counter.
eg:
for(size_t i=0; i<100; i++) wyhash64(seed,i);
more:
for(size_t i=0; i<100; i++) for(size_t j=0; j<100; j++) wyhash64(i,j);
more:
for(size_t i=0; i<100; i++) for(size_t j=0; j<100; j++) wyhash64(seed, (i<<32)|j);
This algorithm can bee ported to GPU and cuda and serves as a parallel PRNG.
global void dropout(float *inp float out, uint64_t seed){
uint64_t id=blockIdx.xblockDim.x+threadIdx.x;
if(wyhash64(seed,id)&1) out[id]=inp[id];
else out[id]=0;
}
Excellent, thank you. I actually need 4 independent streams so I wrote up a quick test harness to write them out interleaved and passed them to BigCrush and PractRand. I used these four values as seeds:
seed[0]: 0x78a236743da49cb
seed[1]: 0xddfac0f2bb9a0fc7
seed[2]: 0x57d60387d2570f66
seed[3]: 0x404ce50a76d36e08
And they passed all the BigCrush tests and 4TB and counting of PractRand.
Last question: is wyhash64 reversible? Thus collision free?
no, it is not reversible nor collision free. However, as a 64 bit PRNG, the space is so large, you can safely use it as BigCrush and Practrand are PRNG standard. More words are: collision is true random but collision free is not true random... Imagine I have a dice to bet with you. You observed 5 rolls: 1,2,3,4,5. If you know the dice is collision free, you can bet on 6 with all your money. But if it is not collision free, it is still fair.
Ok that makes sense, as long as it's deterministic that's my important criteria =D