C++ Programming/Code/Standard C Library/Functions/rand
Tools
General
Sister projects
In other projects
| Syntax | #include<cstdlib>intrand(void); |
The function rand() returns a pseudo-random integer between zero andRAND_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 thesrand() function - otherwise it will consistently return the same numbers when the program is restarted.
Note: |