Archived

This topic is now archived and is closed to further replies.

Fango256

Efficient Random Number Generator in C++

Recommended Posts

I have created an application that needs to create random numbers very quickly. I have seeded it using the time function but this seems to produce the same random number when used quickly. Anyone know of a better seed i can use or a better way of doing it. Cheers.

Share this post


Link to post
Share on other sites
Are you using rand()?


the problem could be that you are seeding it every time before you use it.


wrong:

while(1)
{
srand((unsigned int) time(0));
rand() //however you use it.
}

right:

srand((unsigned int) time(0));
while(1)
{
rand() //However you use it.
}


=======================
Game project(s):
www.fiend.cjb.net

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thanks for the help, much appreciated.

Share this post


Link to post
Share on other sites
Seeding the random number generator with time then calling rand() does not produce real random numbers , but alas it is useful .......... *sigh*.

Hulk -> Hulk Mad hulk smash.
SpiderMan->Oh Shut up , I got gas but you dont hear me bragging about it .

Share this post


Link to post
Share on other sites
There are no such things as ''real random numbers'' anyway. Not when you''re dealing with computers anyway. At least seeding should give you more or less *different* numbers every time you run the program. Fango, if you want more control over your random number function, try investigating the Monte Carlo method - you can make it as fast or as ranging as you need.
r.

"The mere thought hadn''t even begun to speculate about the slightest possibility of traversing the eternal wasteland that is my mind..."

Share this post


Link to post
Share on other sites
There are no such things as ''real random numbers'' anyway. Not when you''re dealing with computers anyway. At least seeding should give you more or less *different* numbers every time you run the program. Fango, if you want more control over your random number function, try investigating the Monte Carlo method - you can make it as fast or as ranging as you need.
r.

"The mere thought hadn''t even begun to speculate about the slightest possibility of traversing the eternal wasteland that is my mind..."

Share this post


Link to post
Share on other sites