Server Help

Non-Subspace Related Coding - Looking for fast random number algorithms

Mine GO BOOM - 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?
Dr Brain - 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
Mine GO BOOM - 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.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group