📄 randomnumbers.cpp
字号:
/* Simple generator for normally distributed random numbers */
#include <iostream>
#include <time.h>
using namespace std;
// Basic method (not quite correct, but fast and sufficient for EAs)
double GetNormalRand (double mean, double variance)
{
double zSum = 0.0;
for (int i=0; i<12; i++) zSum += rand()/(double)RAND_MAX;
zSum -= 6.0;
return zSum*variance + mean;
}
void main(int argc, char **argv)
{
// Initialize the seed of the random number generator with the current time
srand((unsigned)time(NULL));
// Generate 20 quasi-normal distributed random numbers
for (int i=0; i<20; i++)
cout << GetNormalRand(0,1) << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -