// RandZT.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <IOSTREAM>
#include <STDIO.H>
#include <STDLIB.H>
#include <CTIME>
using namespace std;
// [0,1]均匀分布的随机数
double Rand01(double *r)
{
double base, u, v, p, temp1, temp2,temp3;
base = 256.0;
u = 17.0;
v = 139.0;
temp1 = u * (*r) + v;
temp2 = (int)(temp1 / base);
temp3 = temp1 - temp2 * base;
*r = temp3;
p = *r / base;
return p;
}
double RandZT(double u, double t, double *r)
{
int i;
double total = 0;
double result;
for (i= 0; i < 12; i++)
{
total += Rand01(r);
}
result = u + t *(total - 0.6);
return result;
}
int main(int argc, char* argv[])
{
int i;
double r,u,t;
r= 5.0;
u = 2.0;
t =3.5;
cout<<"10 正态分布随机数: "<<endl;
for (i = 0; i < 10; i++)
{
printf("%10.5lf%\n", RandZT(u,t,&r));
}
printf("\n");
return 0;
}
/*
10 正态分布随机数:
19.45078
20.10703
24.26328
24.91953
15.07578
19.23203
23.38828
17.04453
21.20078
25.35703
Press any key to continue
*/
正态分布随机数算法
最新推荐文章于 2023-11-19 01:36:24 发布