Mail Archives: djgpp/1997/07/16/15:40:19
You wrote:
>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.
Just to be picky... this is NOT standard C but C++. C does not have the
reference construct.
>#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;
>}
Nate Eldredge
eldredge AT ap DOT net
- Raw text -