Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using wyhash64 to mix numbers into prngs? #127

Open
smcallis opened this issue Jan 15, 2023 · 5 comments
Open

Using wyhash64 to mix numbers into prngs? #127

smcallis opened this issue Jan 15, 2023 · 5 comments

Comments

@smcallis
Copy link

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?

@wangyi-fudan
Copy link
Owner

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.x
blockDim.x+threadIdx.x;
if(wyhash64(seed,id)&1) out[id]=inp[id];
else out[id]=0;
}

@smcallis
Copy link
Author

smcallis commented Jan 16, 2023

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.

@smcallis
Copy link
Author

Last question: is wyhash64 reversible? Thus collision free?

@wangyi-fudan
Copy link
Owner

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.

@smcallis
Copy link
Author

Ok that makes sense, as long as it's deterministic that's my important criteria =D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants