- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 thanksLink Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are you asking about a hardware, or a software random number generator?
--Scott- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
oh sorry, a software generated instruction for NiosII.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Toysoldier,
You could devote an entire career to this subject ... regardless, here are a few resources I'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- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ahh.... thanks scott...
i thought NIOS would have a built-in code like MATLAB's 'randn'. seems like i am wrong. http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/wink.gif- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I haven't used it myself, but rand() is provided as a part of the C library. You'll find the details in the newlib documentation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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't get the same "random" sequence each time. Having an external counter isn'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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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'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.- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page