delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/09/21:43:39

Date: Thu, 9 Apr 1998 18:42:14 -0700 (PDT)
Message-Id: <199804100142.SAA14864@adit.ap.net>
Mime-Version: 1.0
To: "Jo Voordeckers" <Jo DOT Voordeckers AT village DOT uunet DOT be>, djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: Using random numbers and Allegro

At 08:08  4/9/1998 +0200, Jo Voordeckers wrote:
>I'm trying to use 2 random numbers to put a sprite at a random place on the
>screen, but the way I do it, it allways puts it on the same spot, I'm using
>the DJGPP function
>random() to get a random number but I use it this way to get the number to
>be a maximum of 479 for x (respectively 399 for the y-value), well it's
>kinda complicated to explain, I'm using this virtual screen (480x400 in
>MODE-X 320x240) and use
>-----------------------------------------
>    x=fmod(random(),480);
>-----------------------------------------
>to get the appropriet x-value but it seems to allways give the same number
>(I  use the same way to calculate the y-value)
>I think it somehow has something to do with Allegro initializing stuff like
>the timer-interrupt and such, I dunno actually...Can somebody tell me how to
>do it right/faster/better?

Seed the random number generator first. See the docs for `srandom'.
`time(NULL)' makes a good seed in most cases.

Maybe this should be an FAQ! :) (Yes, I know it's not DJGPP-specific...)

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


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