Mail Archives: djgpp/1997/07/15/09:04:57
Alan Poppleton <Alan DOT Poppleton AT wanadoo DOT fr> wrote in article
<33C91424 DOT 7615 AT wanadoo DOT fr>...
> I need a fast and simple algorithm which can produce a fairly random
> number given two seeds - x and y. Any ideas? It MUST be SIMPLE and
> FAST and it only needs to return a number between 0 and 15.
okay.. Why don't you use standard C. It might be faster to use like chaos
or list of random numbers. I haven't looked into it but this should work
good for most applications.
/*CODE*/
#include <stdlib.h>
#include <time.h>
void randomxy( int&, int&);
int main(void)
{
int foox, fooy;
srandom(time(NULL));
randomxy(foox, fooy);
return 0;
}
void randomxy(int &x, int &y) // using refrences speeds it up by using the
actual varibles
{
int r = random(225);
x = r / 15;
y = r % 15;
}
/*End of CODE*/
There you are. I'm pretty sure it works, and it produces fairly
random numbers. If you want speed you'll just have to use
read a list of randomized numbers.
Micah Cochran
scochran AT shoalsnet DOT com
- Raw text -