dimanche 21 février 2016

Single-use PRNG seedable with consecutive seeds

I need to make a pseudorandom number generator with a particular twist. Instead of generating numbers serially by using the seed from the previous generation for the new generation of a random number as it is usually done, I need a sequence of pseudorandom numbers generated in parallel from a consecutive sequence of seeds.

It would work like this, executed in parallel, each thread producing only a single number, with nothing shared or stored between threads:

thread #0: my_prng(1000) -> 1455191155
thread #1: my_prng(1001) -> 2432152707
thread #2: my_prng(1002) -> 185188134

It's for generating image noise in parallel from a GPU (using OpenCL) so:

  • it should be run fast enough, as in using just a few operations
  • it shouldn't be cryptographically secure, it's just for graphics, it only needs to look about random
  • low periods are just fine, even 2^24 would do
  • it only needs to make 32-bit integers
  • it shouldn't use any memory, no buffers, and not store anything in a variable other than the result (the resulting new seed if there were one would go unused anyway)
  • it cannot rely on calls to rand() as it's not available in OpenCL or rely on any library
  • it shouldn't loop to use serialness (for instance looping 60 times just to make the 60th number)
  • it literally just needs to make a good pseudorandom number from a seed like 1000 that doesn't share a pattern with numbers made from adjacent seeds

None of the typical PRNG algorithms that I've tried could produce sequences from adjacent seeds that looked even remotely random, they're not meant to be seeded and used that way.




Aucun commentaire:

Enregistrer un commentaire