RAD Studio |  |

srand

Header File

stdlib.h

Category

Math Routines

Prototype

void srand(unsigned seed);

Description

Initializes random number generator.

The random number generator is reinitialized by calling srand with an argument value of 1. It can be set to a new starting point by calling srand with a given seed number.

Return Value

None.

Example

Copy Code

    #include <stdlib.h>
    #include <stdio.h>
    #include <time.h>
    int main(void)
    {
       int i;
       time_t t;
       srand((unsigned) time(&t));
       printf("Ten random numbers from 0 to 99\n\n");
       for(i=0; i<10; i++)
           printf("%d\n", rand() % 100);
       return 0;
    }

Portability

POSIX | Win32 | ANSI C | ANSI C++
+ | + | + | +

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!