jeudi 22 octobre 2015

Pseudorandom hash of two integers

I need a NxN matrix with 16bit or 32bit pseudorandom uniformaly distributed numbers over the whole range of values. N is unfortunately very large (at least 1e6), so it can not be pregenerated (That would take about a TB of memory). The only viable option I can think of is using a hash of my indices i and j as matrix elements.

There are plenty of integer hash functions available, but I am not sure which ones are suitable for two reasons.

-Only 32bit unsigned integer operations available. Since N is at least 2^20 I can not naively concatenate the two indices into one 32bit key without creating unnecessary collisions.

-Pseudorandomness is important here, I am not building a hashtable. Most integer hashes I found are designed for hashtables and don't have very strong requirements.

A possible solution would be taking a cryptographic hash like SHA-2, but performance is important and that is just too expensive.

A suggestions on how to combine two 32bit uints into one wile avoiding collisions patterns would already help a great deal, since I could then pick from the whole range of 32bit to 32bit hashes.

Some insight on which 32bit to 32bit hashes have good randomness would also be much appreciated.

Pregenerating 1 or 2 Arrays of N random numbers is no problem if it helps.

In case it matters, the target are GPUs I am writing in recent versions of GLSL.




Aucun commentaire:

Enregistrer un commentaire