background image

 

返回值

 

范例
/* 产生介于 1 到 10 间的随机数值,此范例与执行结果可与 rand()参照*/ 
#include<time.h> 
#include<stdlib.h> 
main() 

int i,j; 
srand((int)time(0)); 
for(i=0;i<10;i++) 

j=1+(int)(10.0*rand()/(RAND_MAX+1.0)); 
printf(" %d ",j); 

 

执行
5 8 8 8 10 2 10 8 9 9 
2 9 7 4 10 3 2 10 8 7