Srand (unsigned) time (NULL) and use and understanding of rand () functions, srandrand
1. First, let's talk about the rand () function.
The rand () function is equivalent to a random number generator. The generated number ranges from 0 to 32767
In Perl, Srand () provides random number seeds for use by rand (), and Rand () produces random number generators.If Srand () is not invoked before the first call to Rand (), then the system automatically invokes Srand () for you.Calling Srand ()
The random number of a computer is generated by a pseudo-random number, which is a sequence of small m-polynomial, in which each small sequence has an initial value, that is, a random seed. (Note: The period of the small m polynomial sequence is 6553
First we have a general view of Rand&srand: Srand initializes random seeds, Rand generates random numbers, which are explained in detail below.Rand(generates random numbers)Header file: #include define function: int rand (void) function Description:
Random numbers of computers are generated by pseudo random numbers, which are produced by the small m polynomial sequence, in which each small sequence has an initial value, i.e. random seed. (Note: The cycle of a small m polynomial sequence is 6
I. Rand ()
Function Name: RandFunction: random number generatorUsage: int rand (void );
Header file: stdlib. h
Function Description:
The internal implementation of rand () is done by the linear same remainder method. It is not a real random number.
Using some computer intelligent algorithms (GA, PSO, Ann etc .) during simulation, you often need to randomly generate the initial population (initial sample) to see Generate pseudo-random numbers for these two functions ~~~1. Generate a real
http://zhangjunhd.blog.51cto.com/113473/197020
Random numbers of computers are generated by pseudo random numbers, which are produced by the small m polynomial sequence, in which each small sequence has an initial value, i.e. random seed. (Note: The
I. rand ()
Function Name: RandFunction: Random number generatorUsage: int rand (void);
The header file: stdlib.h
Function Description:
The internal implementation of RAND () is done with linear congruential, it is not a true random number, because
In programming, it is often necessary to use random numbers, of course, the program (function) itself can not generate so-called real random number, but also need a random seed, and then according to the established algorithm to calculate a definite
Rand function and Srand functionFirst we have a general view of Rand&srand: Srand initializes random seeds, Rand generates random numbers, which are explained in detail below.1. Rand (generate random number)Table header files: #include define
Reference Original address: https://www.cnblogs.com/afarmer/archive/2011/05/01/2033715.htmlThe random number of a computer is generated by a pseudo-random number, which is a sequence of small m-polynomial, in which each small sequence has an initial
Using some computer intelligent algorithms (GA, PSO, ANN etc .) during simulation, you often need to randomly generate the initial population (initial sample) to see Generate pseudo-random numbers for these two functions ~~~1. Generate a real
In some productsSource codeSuch a statement is often found,
Srand (unsigned (Time (null )));
Why is this actually quite simple.
1. The time () function indicates the number of seconds from 00:00:00 to the current time. The time (null) function
We often need to use random numbers in the process of programming problem solving. Since the computer is a logic-based machine, it is impossible to be truly random (presumably a quantum computer can?). )。 So the computer generates pseudo-random
Excerpt from: Baidu Encyclopedia The prototypes of these two functions in stdlib.h are: int rand (); void srand (unsigned int); ? in the standard C library, the function RAND () can generate a random number between 0~rand_max, where Rand_max is an
Srand () is to give rand () seeds seed.If the Srand value is the same for each input, the random number generated for each run is the same.Taking a fixed number as a seed is a disadvantage. The usual practice is to srand ((unsigned) time (NULL) in
In the C language, two functions are included in the header file, C ++, and the standard library (included in ).
The srand function is the initialization function of the random number generator.
Prototype: void srand (unsigned seed );
The rand
Intelligence on computersAlgorithm(GA, PSO, Ann etc.) randomly generated during simulationInitial population(Initial sample), let's take a look atPseudo-Random NumberGenerate it ~~~
1. Generate a real number and an integer between [a, B]
/*
Reprint: http://blog.csdn.net/kongfanyu/article/details/6387642 Computer There is no way to generate a real random number, is to use algorithm simulation, so you only call Rand, every time out something is the same. After a seed is set, different
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.