那背后有一些逻辑或原理吗?
数字是否完全随机生成?
假设我正在运行此程序:
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
int main()
{
/*
Declare variable to hold seconds on clock.
*/
time_t seconds;
/*
Get value from system clock and
place in seconds variable.
*/
time(&seconds);
/*
Convert seconds to a unsigned
integer.
*/
srand((unsigned int) seconds);
/*
Output random values.
*/
cout<< rand() << endl;
cout<< rand() << endl;
cout<< rand() << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它显示的内容:http: //img14.imageshack.us/img14/1538/98271820.png
它显示205两次.