#### Archived

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

# Efficient Random Number Generator in C++

This topic is 6077 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 on other sites
Thanks for the help, much appreciated.

##### 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 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 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..."

• ### Forum Statistics

• Total Topics
628701
• Total Posts
2984290

• 22
• 10
• 9
• 13
• 13