Author |
Message |
Mine GO BOOM Hunch Hunch What What
Age:40 Gender: Joined: Aug 01 2002 Posts: 3614 Location: Las Vegas Offline
|
Posted: Tue Mar 14, 2006 12:10 am Post subject: Looking for fast random number algorithms |
|
|
|
|
I'm currently working with a 16bit processor, and I am looking to find a simple random number generator that works well enough in a small range, such as between 0 and 1000, or the lower (or upper) 10 bits at least, but most importantly be able to get close to 50-50 on coin flips and 25-25-25-25 on a 4-way choice. Being 45-55 is perfectly acceptable, but more than 40-60 is pushing it.
It doesn't need to be fancy, as speed is much, much more important than randomness. Seeding of the random number generator will most likely be shitty, as its environmental sensory will be in a very binary world. Any ideas?
|
|
Back to top |
|
|
Dr Brain Flip-flopping like a wind surfer
Age:38 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Tue Mar 14, 2006 1:02 am Post subject: |
|
|
|
|
I've always used a LFSR for my PRNGs in embedded systems. I don't have any code handy, but it'd be in asm and probably worthless to you anyway.
Here's a wiki article to get you started: http://en.wikipedia.org/wiki/Linear_feedback_shift_register _________________ Hyperspace Owner
Smong> so long as 99% deaths feel lame it will always be hyperspace to me
|
|
Back to top |
|
|
Mine GO BOOM Hunch Hunch What What
Age:40 Gender: Joined: Aug 01 2002 Posts: 3614 Location: Las Vegas Offline
|
Posted: Tue Mar 14, 2006 3:24 am Post subject: |
|
|
|
|
Thanks, works pretty damn well. Might as well put up a copy of the source here for anyone else interested. Has hard coded values in, though through random trial and error, was a pretty good initial seed value for 1 and 2 bit random numbers, which are the important ones. Don't want to do the math for finding an optimial starting seed value for a 10bit number to be random enough, as that will only be called rarely so will be random enough.
My code of Linear Feedback Shift Register for a 16bit processor
prng.c - 3.53 KB
File downloaded or viewed 47 time(s)
|
|
Back to top |
|
|
|