Random Number Generator

Hello guys! I have a little problem. I need to do a Monte Carlo Algorithm and I need to get some random numbers.
I was reading about Mersene Twister but I don’t know how to use that to generate random numbers.

If somebody has an example to give me and help me how can I get some Random Number generator Algorithm for cuda programs? please help me.

How about the SDK example?

(By the way it would be nice if Nvidia could fix the link anchors on that page. You will likely have to scroll down or search for MersenneTwister on that page yourself.)

I would suggest to take a look at the CURAND library. See: http://developer.download.nvidia.com/compute/cuda/4_0/toolkit/docs/CURAND_Library.pdf

@tera: Could you be more specific please as to what exactly is broken? I tried a bunch of the download links on the page you pointed to and they appear to work. Since you spoke of “link anchors” (a term I am unfamiliar with) I suspect you mean something else besides the links themselves. I’d be happy to pass any actionable information to our web team. Thanks!

Thanks Norbert. The download links do indeed work. What doesn’t is my link in the post above. Even though it ends on “#MersenneTwister” which I copied straight from the link symbol it leads to the top of the page instead of directly to the Mersenne Twister example because all the html anchor tags on that page miss a name=“…” attribute.

Still not sure what exactly this means, but I assume it does mean something to the team maintaining the website :-) I’ll follow up with them.

Sorry for my confusing description -it probably already was too late in the morning for me and time to go to bed.

The HTML source of that page contains “anchors” that are supposed to allow direct linking to a specific example:

<span class="itemName" name="path">MersenneTwister <a href="#MersenneTwister"><img alt="For a direct link to this sample, right-click and copy the URL (shortcut) of this link icon." class="anchorImage" src="http://developer.download.nvidia.com/compute/DevZone/C/html/images/link.jpg" /></a></span>

For them to actually work, they would also need a [font=“Courier New”]name[/font] attribute:

<span class="itemName" name="path">MersenneTwister <a name="MersenneTwister" href="#MersenneTwister"><img alt="For a direct link to this sample, right-click and copy the URL (shortcut) of this link icon." class="anchorImage" src="http://developer.download.nvidia.com/compute/DevZone/C/html/images/link.jpg" /></a></span>

The same applies to all other examples. As far as I can remember, it used to work a while ago though.

Thanks for following up with the web team!

Hi, njuffa, could I assume you are familiar with CURAND? I have a question on CURAND. I want to get same random number series on both CPU and GPU. But using standard ways I failed to do it. I need some strange trick to reach this purpose. I wonder if it’s a problem in CURAND or I missed something. See here for my test code and more details. Thanks.

Has the web team ever come back to this?

I did notify the web team at the time. I don’t recall anything beyond that, it is simply too long ago. I will check whether the anchors work now, and ping the web team again if they don’t.

No, they don’t work yet. It’s just a matter of replacing

<a href="#MersenneTwister">

with

<a name="MersenneTwister" href="#MersenneTwister">

for all examples on the page.

Thanks again!

Sorry for the inconvenience. I fired off another email, relaying your proposal on how to fix the anchors.

Bump. I just linked an example again in another thread and noticed they still don’t work.

I understand it’s not the most important thing in the world. Then again it would be so simple to fix.

Sure would be nice if somebody would publish an example higher level interface with some complexity hiding.

Something like:

void myRandInit(); // callable from host

device float myRandU(); // callable from a CUDA kernel

Which calls CURAND or Mersenne inside. I’m having a hard time finding the forest through all the trees.