[gameprogrammer] Re: Making random numbers in C++

Thanks for the reply, guyz
I just figured it out.
 
What I was doing , was this:
 
for (int i=0;i<10000;i++)
{
 
//some code
 
srand (time(NULL));
 
//some code
 
}
 
whereas srand should be out of the loop.
 
 
this srand was iterating again and again,
and was generating 1 integer for 1 sec.
 
thanks for your reply, I really appriciate that.
> Date: Wed, 31 Dec 2008 20:11:37 +0000> From: brian.ripoff@xxxxxxxxx> To: 
> gameprogrammer@xxxxxxxxxxxxx> Subject: [gameprogrammer] Re: Making random 
> numbers in C++> > That should not happen. Can you post a complete example 
> that> demonstrates this behaviour. My computer can generate a million random> 
> numbers in a handful of milliseconds, according to a quick,> unoptimised 
> program I threw together, compiled without optimisation> either.> > On Wed, 
> Dec 31, 2008 at 7:53 PM, Azeem Zaheer <azeem_841@xxxxxxxxxxx> wrote:> > I am 
> making a program in which I need about 10,000 "random" numbers ranging> > 
> from 1 to 10.I have to make it in> > C++.So, when I use srand(time(NULL)); it 
> works..but it is tooo slow.> > I takes 1 whole second to process and generate 
> 1 number.> > I will have to wait 1000 secs, which is hell of a time.Please 
> suggest me> > someway to make random numbers> > more quicker.Just tell me how 
> to make 1 random number in 1 millisecond or> > even less.> > 
> ---------------------> To unsubscribe go to 
> http://gameprogrammer.com/mailinglist.html> > 
_________________________________________________________________
Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.

http://www.microsoft.com/windows/windowslive/photos.aspx

Other related posts: