Article View: comp.sys.ibm.pc.programmer
Article #1575Re: Random Number Generation in Turbo C 2.0
From: Gunther Wil Anderson
Date: Wed, 14 Mar 1990 19:06
Date: Wed, 14 Mar 1990 19:06
41 lines
1524 bytes
1524 bytes
The code is straightforwardly presented in _The Science of Fractal
Images_ by Heinz-Otto Peitgen and (someone else, I forgot whom). I
haveincluded it here, but that book is quite worthwhile for not only
fractals of all types in theory and practise, but also general random
number algorithms.
#define MAXLEVEL 200
int Arand, Nrand;
double GaussAdd, GaussFac;
double delta[MAXLEVEL];
void InitGauss(seed)
int seed;
{
Nrand = 4;
Arand = INT_MAX;
GaussAdd = sqrt(3.0*(double)Nrand);
GaussFac = 2*GaussAdd/((double)Nrand*(double)Arand);
srand((unsigned)seed);
}
double Gauss()
{
double sum;
int i;
sum = 0.0;
for(i = 1; i <= Nrand; i++)
sum += (double)rand();
return(GaussFac*sum - GaussAdd);
}
And viola, Gaussian random variables.
Hope this helps,
Gunther Anderson
gunther@jhunix.hcf.jhu.edu
gunther@jhuvms.hcf.jhu.edu
gunther@crabcake.cs.jhu.edu
Technical Details
Message-ID:
<4491@jhunix.HCF.JHU.EDU>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!jhunix!guntherReferences:
<21720@netnews.upenn.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!jhunix!gunther From: gunther@jhunix.HCF.JHU.EDU (Gunther Wil Anderson) Newsgroups: comp.sys.ibm.pc.programmer Subject: Re: Random Number Generation in Turbo C 2.0 Summary: The Science of Fractal Images Keywords: Normal/Gaussian Dist. Message-ID: <4491@jhunix.HCF.JHU.EDU> Date: 14 Mar 90 19:06:34 GMT References: <21720@netnews.upenn.edu> Reply-To: eisen@jhunix.UUCP (Gunther Wil Anderson) Distribution: usa Organization: The Johns Hopkins University - HCF Lines: 40