⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 randomnumbers.cpp

📁 一个十分简单有效的正态随机数产生程序, 相信就是你想要的哦.
💻 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 + -