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

📄 randn.cpp

📁 Visual C++写的
💻 CPP
字号:
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "randn.h"

double randn(const double Mean, const double SquareMargin)
{
	const double PI = 3.1415926;
	double model = 4294967296.0;
	double multiplicator = 663608941.0;
	double temp_a, temp_b;
	static double seed = (double)time(NULL);
	
	seed *= multiplicator;
	seed -= (int)(seed/model) * model;
	temp_a = seed/model;

	seed *= multiplicator;
	seed -= (int)(seed/model) * model;
	temp_b = seed/model;

	double norm_randn = sqrt(-2*log(temp_a))*cos(2*PI*temp_b);
	double gauss_rand = Mean + norm_randn*SquareMargin;
	return(gauss_rand);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -