delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/11/26/19:46:39

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: random() returns predictable values
Date: Thu, 27 Nov 1997 18:51:06 +0000
Organization: Two pounds of chaos and a pinch of salt
Lines: 31
Message-ID: <347DC11A.408D@cs.com>
References: <347C970A DOT 3D0E AT swipnet DOT se>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp244.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Deltaman wrote:
> 
> Are there any good random routines to substitute random()?
> It returns too predictable values to be of real value to me. Even with a
> random seed it still returns the same values several times in a row.
> Does anyone know of a way to get more random numbers?

This is the first time anybody has reported any such problem with
random().  Are you sure you are seeding it?  The clock value is a good
seed to use:

#include <stdlib.h>
#include <time.h>

    srandom( (int) time( NULL ) );
    ...
    x = random() % 100;

Also remember, you only need to use srandom() once.

If this doesn't help, please post some more details, like some sample
program code that generates non-random numbers.  The period of random()
is supposed to be at least 2^32.

-- 
---------------------------------------------------------------------
|      John M. Aldrich       | "A woman is not property, and hus-   |
|       aka Fighteer I       | bands who think otherwise are living |
|   mailto:fighteer AT cs DOT com   | in a dreamworld."                    |
| http://www.cs.com/fighteer |                - Lazarus Long        |
---------------------------------------------------------------------

- Raw text -


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