delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/09/18/16:54:09

Message-ID: <37E3E460.E60AAC43@pepparkakor.demon.nl>
Date: Sat, 18 Sep 1999 21:13:36 +0200
From: Roger <roger AT pepparkakor DOT demon DOT nl>
X-Mailer: Mozilla 4.61 [en] (Win95; I)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Random number
Reply-To: djgpp AT delorie DOT com

Hi,everyone.

I have a problem with random number.I try this:

First I make a class:

class Number
{
public:
Number() {srandom((unsigned)time(0));}
Number(unsigned seed) {srandom(seed);}
int MyNumber(int min,int max)
{
if (max<0)max=0;
if((min==max) && (min=0))return 0;
return random()%(max-min+1)+min;
}
};

then in my program i do a loop,like this:

for(p=1;p<10;++p)
{
Number random;
C[p]=random.MyNumber(0,100);
}

And I got every time same number on all C's!!

Why? I have read everything on the net and in my book,and i can't solve
it.

Thanks for a wonderful list




- Raw text -


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