delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/16/15:40:19

Date: Wed, 16 Jul 1997 12:39:27 -0700 (PDT)
Message-Id: <199707161939.MAA08221@adit.ap.net>
Mime-Version: 1.0
To: scochran AT shoalsnet DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: Fast random number generator
Cc: djgpp AT delorie DOT com, Alan DOT Poppleton AT wanadoo DOT fr

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019