JCurand

Java bindings for CURAND



JCurand is a library that makes it it possible to use CURAND, the NVIDIA CUDA random number generator (RNG), in Java applications.

You may obtain the latest version of JCurand in the Downloads section.



Application


JCurand provides easy access to CURAND, and thus allows users to efficiently create high-quality pseudorandom and quasirandom numbers from Java programs - for the cases where java.util.Random is just not random enough...


The following code snippet shows how to set up a random number generator and create as set of pseudorandom numbers on the device, which are then copied to Java:
// Allocate device memory 
Pointer deviceData = new Pointer();
cudaMalloc(deviceData, n * Sizeof.FLOAT);

// Create and initialize a pseudo-random number generator 
curandGenerator generator = new curandGenerator();
curandCreateGenerator(generator, CURAND_RNG_PSEUDO_DEFAULT);
curandSetPseudoRandomGeneratorSeed(generator, 1234);

// Generate random numbers 
curandGenerateUniform(generator, deviceData, n);

// Copy the random numbers from the device to the host 
float hostData[] new float[n];
cudaMemcpy(Pointer.to(hostData), deviceData, 
    n * Sizeof.FLOAT, cudaMemcpyDeviceToHost);< /code>