# problem with random

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

## Recommended Posts

Hi all... I'm working with a random function, the problem is when I use seconds as my random seed... In my game I need to call the random function 15 times consecutively, the computer is so damn quick with these calculations so that random seed (seconds) is similar for all of the 15 random functions (which cause for the same numbers to be generated). any ideas how to solve that??

##### Share on other sites
You only call the seed function once, usually at program startup.

##### Share on other sites
usually, you only seed your random number generator once, at the beginning of the program. Then each time you call random, you'll get a different value.

##### Share on other sites
Use microseconds (or even nanoseconds) instead. i.e. the u_sec component returned by gettimeofday() on unix.

##### Share on other sites
Quote:
 Original post by jimmySmileHi all...I'm working with a random function, the problem is when I use seconds as my random seed... In my game I need to call the random function 15 times consecutively, the computer is so damn quick with these calculations so that random seed (seconds) is similar for all of the 15 random functions (which cause for the same numbers to be generated).any ideas how to solve that??

The reason it's called a random "seed" is that you only have to plant it once, and then pick as many random numbers as you like off the resulting tree. If you plant several genetically identical seeds, and pick the first number off each tree, you can hardly be surprised when they're all the same. (Of course, sometimes it's useful to be able to reproduce a series of random numbers, for example to verify a random simulation.)

Except that "plant" and "tree" aren't technical terms here the way that "seed" is. :)

##### Share on other sites
Right you are guys... didn't even thought in that direction. (god I such an a**)

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 11
• 15
• 9
• 10
• 13
• ### Forum Statistics

• Total Topics
633004
• Total Posts
3009840
• ### Who's Online (See full list)

There are no registered users currently online

×