Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Valued Contributor III
719 Views

"Random" Instruction

Hi, 

 

can anyone tell me how to generate random numbers in the NIOS II , for the IDE software in C ? 

 

http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/huh.gif  

 

thanks
0 Kudos
7 Replies
Highlighted
Valued Contributor III
4 Views

Re: "Random" Instruction

Are you asking about a hardware, or a software random number generator? 

 

--Scott
0 Kudos
Highlighted
Valued Contributor III
4 Views

Re: "Random" Instruction

oh sorry, a software generated instruction for NiosII.

0 Kudos
Highlighted
Valued Contributor III
4 Views

Re: "Random" Instruction

Hi Toysoldier, 

 

You could devote an entire career to this subject ... regardless, here 

are a few resources I&#39;ve used in the past that may be helpful: 

 

http://csrc.nist.gov/rng (http://csrc.nist.gov/rng) -- everything you wanted to know and more ;-) 

http://www.embedded.com/showarticle.jhtml?...icleid=20900500 (http://www.embedded.com/showarticle.jhtml?articleid=20900500) -- nice article with some C code 

http://www.opencores.org/projects.cgi/web/...ng_lib/overview (http://www.opencores.org/projects.cgi/web/rng_lib/overview) -- VHDL code 

 

Hope this is helpful. 

 

Regards, 

--Scott
0 Kudos
Highlighted
Valued Contributor III
4 Views

Re: "Random" Instruction

ahh.... thanks scott... 

 

i thought NIOS would have a built-in code like MATLAB&#39;s &#39;randn&#39;. 

 

seems like i am wrong. http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/wink.gif
0 Kudos
Highlighted
Valued Contributor III
4 Views

Re: "Random" Instruction

I haven&#39;t used it myself, but rand() is provided as a part of the C library. You&#39;ll find the details in the newlib documentation.

0 Kudos
Highlighted
Valued Contributor III
4 Views

Re: "Random" Instruction

A good way to get a random number is to use the one out of the C library like monkeyboy said, and seed it with an external hardware counter that you let count away independently (avalon slave that you can read from). The seed value helps randomize the rand() call so that you don&#39;t get the same "random" sequence each time. Having an external counter isn&#39;t going to be perfect but it will give you a much more random sequence since the likelyhood of the value producing the same seed all the time is going to be really rare.

0 Kudos
Highlighted
Valued Contributor III
4 Views

Re: "Random" Instruction

It all depends what you need the random number for. rand() is good enough for a lot of things, but it generates a fixed sequence of numbers which won&#39;t be appropriate for some applications. 

 

If you want a real random number then you need to drive it from some sort of non-deterministic process as the earlier links suggested.
0 Kudos