69_伪随机数的生成

来源:互联网 发布:photoshop cc mac版 编辑:程序博客网 时间:2024/05/21 15:44
//_69_伪随机数的生成//_69_main.cpp//用系统时间通过使用srand()和rand()函数随机的初始化rand()函数//两个函数包含在<stdlib.h>中#include <stdio.h>#include <stdlib.h>#include <time.h>int main(){long time1 = time(NULL);//返回系统当前时间printf("%ld\n",time1);int time2 = (unsigned)time1/2;printf("%ld\n",time2);//以系统时间为参数,为即将生成的伪随机数序列设置起点srand(time2);//生成十个伪随机数序列for(int i=0;i<10;i++)printf("%d ",rand());printf("\n");system("pause");return 0;}

0 0
原创粉丝点击