Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

C++ Programming/Code/Standard C Library/Functions/rand

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

rand #include <cstdlib> int rand( void ); The function rand() returns a pseudo-random integer between zero and RAND_MAX. An example: srand( time(NULL) ); for( i = 0; i < 10; i++ ) printf( "Random number #%d: %d\n", i, rand() ); The rand() function must be seeded before its first call with the srand() function - otherwise it will consistently return the same numbers when the program is restarted. The generation of random numbers is essential to cryptography. Any stochastic process (generation of random numbers) simulated by a computer, however, is not truly random, but pseudorandom; that is, the randomness of a computer is not from random radioactive decay of an unstable chemical isotope, but from predefined stochastic process, this is why this function needs to be seeded. Related topics srand