Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a seed in terms of generating a random number? [duplicate]

What is a seed in terms of generating a random number?

I need to generate hundreds to thousands of random numbers, I have read a lot about using a "seed". What is a seed? Is a seed where the random numbers start from? For example if I set my seed to be 5 will it generate numbers from 5 to whatever my limit is? So it will never give me 3 for example.

I am using C++, so if you provide any examples it'd be nice if it was in C++.

Thanks!

like image 703
SirRupertIII Avatar asked Feb 16 '13 20:02

SirRupertIII


People also ask

What is the seed of a random number?

What is a Random Seed? A random seed is a starting point in generating random numbers. A random seed specifies the start point when a computer generates a random number sequence. This can be any number, but it usually comes from seconds on a computer system's clock (Henkemans & Lee, 2001).

What is seed in random state?

A random seed (or seed state, or just seed) is a number (or vector) used to initialize a pseudorandom number generator. For a seed to be used in a pseudorandom number generator, it does not need to be random.

What is the use of seed in random number generator?

The seed() method is used to initialize the random number generator. The random number generator needs a number to start with (a seed value), to be able to generate a random number. By default the random number generator uses the current system time.

What does the number in set seed mean?

set seed # specifies the initial value of the random-number seed used by the random-number functions, such as runiform() and rnormal(). set seed statecode resets the state of the random-number functions to the value specified, which is a state previously obtained from creturn value c(seed).


1 Answers

What is normally called a random number sequence in reality is a "pseudo-random" number sequence because the values are computed using a deterministic algorithm and probability plays no real role.

The "seed" is a starting point for the sequence and the guarantee is that if you start from the same seed you will get the same sequence of numbers. This is very useful for example for debugging (when you are looking for an error in a program you need to be able to reproduce the problem and study it, a non-deterministic program would be much harder to debug because every run would be different).

If you need just a random sequence of numbers and don't need to reproduce it then simply use current time as seed... for example with:

srand(time(NULL)); 
like image 153
6502 Avatar answered Oct 11 '22 10:10

6502