www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/23/18:19:09

Message-ID: <3310CDBF.727D@pobox.oleane.com>
Date: Mon, 24 Feb 1997 00:07:43 +0100
From: Francois Charton <deef AT pobox DOT oleane DOT com>
Organization: CCMSA
MIME-Version: 1.0
To: steve wilcox <stewilcox AT slicksoft DOT demon DOT co DOT uk>
CC: djgpp AT delorie DOT com
Subject: Re: not so random numbers
References: <856730848 DOT 1887 DOT 0 AT slicksoft DOT demon DOT co DOT uk>

steve wilcox wrote:
> 
> hi im having probs creating random numbers in djgpp i have made a
> define like so :
> #define randomize() srand((unsigned)time(NULL))
> 
> and im my code i call randomize() first but i still dont get random
> numbers using x = random()%100;
> 
> anyone know whats wrong ?

The DJGPP C library has two random numbers generators : 
rand() and random(). They are two different functions, not aliases for 
the same (random() being, I'm told, more random than rand(), but more 
expensive to compute).

These two generators have different seeding functions : srand() for 
rand(), and srandom() for random().

If your code is just like what you wrote above, you are calling srand() 
to initialise rand() (this is ok) but then you call random(), which is 
not seeded.

Either use srandom() in the randomize() function, or call rand() after 
(*not both* ;-)).

Regards
Francois

- Raw text -


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