views:

609

answers:

2

I am attempting to build a particle system utilizing CUDA to do the heavy lifting. I want to randomize some the particles initial values like velocity and life span. The random numbers don't have to be super random since its just for visual effect. I found this post that addresses the same subject

http://stackoverflow.com/questions/837955/random-number-generator-in-cuda

That suggests a linear congruential is the way to go. It seems like it should be simple to implement, but I am having trouble getting anything useful of my implementation. Can anyone provide some code that will run in device?

I am using CUDA with VC++ on Windows 7 64bit

+3  A: 

CUDA pseudo random number generators are

  1. included in the NVidia SDK eg C/src/MersenneTwister/ and C/src/quasirandomGenerator

  2. available as separate papers and source:

    2.a Langdon's paper and Langdon's source code

    2.b Mersenne Twister on GPU

Dirk Eddelbuettel
+2  A: 

Depending on your requirements there are a number of open source options. There are also several commercial options such as NAG who have implemented l'Ecuyer's MRG32k3a. Be wary of using an LCG if you need to ensure that your streams are not correlated - you can use leapfrog/splitting but you'll need a very long period!

If you want to go open source then you should definitely consider using thrust for it's simplicity. There are also some RNGs in the NVIDIA SDK, including the Mersenne Twister PRNG sample (MT607, MT19937 is on the forums) and the Sobol and Niederreiter QRNGs.

Finally, CUDPP also has a random number generator.

Tom