次の方法で共有


srand

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at srand.

Sets the starting seed value for the pseudorandom number generator.

Syntax

void srand(  
   unsigned int seed   
);  

Parameters

seed
Seed for pseudorandom number generation

Remarks

The srand function sets the starting point for generating a series of pseudorandom integers in the current thread. To reinitialize the generator to create the same sequence of results, call the srand function and use the same seed argument again. Any other value for seed sets the generator to a different starting point in the pseudorandom sequence. rand retrieves the pseudorandom numbers that are generated. Calling rand before any call to srand generates the same sequence as calling srand with seed passed as 1.

Requirements

Routine Required header
srand <stdlib.h>

For additional compatibility information, see Compatibility in the Introduction.

Example

See the example for rand.

.NET Framework Equivalent

System::Random Class

See Also

Floating-Point Support
rand