Random number - normally distributed

D

David Veeneman

Hi-- I'm looking for a simple function to generate a normally distributed
series of random numbers using the .NET Random class. The Random class
generates uniformly distributed random numbers, and I need numbers that are
normally distributed (that fall under a bell-shaped curve). Plus, I need to
be able to document the method by citing a standard formula or text as its
source.

Has anyone got such a method handy? Thanks in advance.

David Veeneman
Foresight Systems
 
S

Steve Walker

David Veeneman said:
Hi-- I'm looking for a simple function to generate a normally distributed
series of random numbers using the .NET Random class. The Random class
generates uniformly distributed random numbers, and I need numbers that are
normally distributed (that fall under a bell-shaped curve). Plus, I need to
be able to document the method by citing a standard formula or text as its
source.

Has anyone got such a method handy? Thanks in advance.

You could use Central Limit Theorem; although the distribution generated
by the Random class is uniform, the means of samples from it will be
normally distributed. The output from this looks normal to me, but you
could always test that statistically:

class Class1
{

[STAThread]
static void Main(string[] args)
{
using(StreamWriter s = File.CreateText(@"C:\file.txt"))
{
for(int j=0;j<10000;j++)
{
int i = GetRandom();
Console.WriteLine(i);
s.WriteLine(i);
}
}
}
static Random r = new Random();
static int GetRandom()
{
int total=0;
for(int i=0;i<20;i++)
{
total+=r.Next(100);
}
return total/20;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top