#include stdio.h#include stdlib.h#include time.hint main () {int i, n;time_t t;
编程学习网为您整理以下代码实例,主要实现:C语言库rand()函数,希望可以帮到各位朋友。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main () {
int i, n;
time_t t;
n = 5;
/* Intializes random number generator */
srand((unsigned) time(&t));
/* Print 5 random numbers from 0 to 49 */
for( i = 0 ; i < n ; i++ ) {
printf("%d\n", rand() % 50);
}
return(0);
}