Curand (linux 64-bit)

I’d like to use the curand library, i need random numbers that will be used by threads in a kernel. Is it possible to create a single generator (from host side) and each thread will “ask” a number when needed? (i don’t want to generate a huge array of number and store it on the global memory, because i need a lot of numbers and i use them only one time)

i didn’t manage to use the curand device functions, i tried to include (#include <curand_kernel.h>), but nvcc does’t find the libraries, i guess i have add them somewhere. I’m not familiar at all with this, could you tell me how to add the libraries and if needed how to compile them? (my system is linux 64-bit)


I’m not sure what you intend to do with the NVCC and the curand_kernel.h - was this just an attempt to create an own kernel that you wanted to use instead of JCurand?

In general, I think that the intended application case of CURAND is not to “provide random numbers on request”. Depending on how you are going to use the random numbers, you might consider creating “some” random numbers in “batches”. For example, when you want to launch a Kernel with 256 Threads, you could create 256 random numbers and pass in the array to the kernel (each kernel could then pick “his” number based on the threadIdx). When you know that you want to call the kernel 3 times, you could create 3256 numbers. When you want to call the kernel 1000 times, you could create 10256 random numbers for the first calls, then 10*256 numbers for the next calls, and so on. (Just an idea, not sure if it matches your intended application pattern…)


Hello marco,
actually, i have though about this solution, it could be possible, but that could consume a lot of memory.
if i want to do this, do i need to compile libraries for my system?

i read in the CURAND_library.pdf file of the documentation:

The second piece of CURAND is the device header file, /include/
curand_kernel.h. This file defines device functions for setting up random
number generator states and generating sequences of random numbers. 
User code may include this header file, and user-written kernels may then call the
device functions defined in the header file. This allows random numbers to
be generated and immediately consumed by user kernels without requiring
the random numbers to be written to and then read from global memory.

that could be a better solution, but i’m not sure how to include the header file…maybe this is more a CUDA question?

Ah, I see. Admittedly, I did not yet really notice the “kernel level interface” for CURAND, and don’t know how it is used. What does it complain about when you try to include the curand_kernels.h?

when i compile, nvcc says that it doesn’t find the file „curand_kernel.h“.
as i don’t know where he seaches them and where to find them, i tried to add some random ( :p) files i found ont the web (curand.h, curand_kernel.h, curand_precalc.h) in the folder of the .cu file, but honestly i don’t know what is a .h file and how to use it.

I tried your JCurand exemple, and i works (also as an imageJ plugin, easy to visualize :stuck_out_tongue: ) so if it’s too complicated and if you don’t have interest in using the divice side of curand, don’t bother finding a solution, i’ll adapt my algorithm to your solution (generating the numbers and storing them before)
Thanks again,


In general, when you want to compile a file that #includes a header file, you have to specify the include path for the NVCC, roughly like
nvcc -cubin -I"your/path/to/header" -o outputFile.cubin
Where “your/path/to/header” is the path to the directory which contains the desired .h file. It may be a little bit difficult to work out further dependencies (the header file might include another header file, and so on) but with some diligence it should be possible to figure out the required files.