# Deriving points conforming to bell curve

1. Jun 21, 2010

### MichaelEber

I am writing a system that collects values from our devices (CRAH, Generators, etc) compute the trend of the data, and determine if an alarm should be raised.

For testing I have a point generator and I want it to follow fairly realistic norms. Currently I generate a new point as:

p.Y = p'.Y + rand.NextDouble()-.5; | p' is the previous point, and Y is the value being generated (p.X is a point in time)

This is taking the value of the last point and adding a random variant that is +- .5.

The problem is that rand will generate a totally linear grouping of numbers. What I want to do is put that point through a computation so that the next point follows a bell curve. Therefore it is more likely to generate a difference of (say) .09 - -.09 then it is .5 and .5 is closer to a 0 chance of generation than any other point.

I've used google and searched a few math forums but most of the discussion is from data analysis after the fact not during generation of the points.

Any suggestions on a formulae that would produce the desired distribution?

2. Jun 21, 2010

### EnumaElish

Do you mean to replace p.Y = p'.Y + rand.NextDouble()-.5 with
p.Y = p'.Y + NormallyDistributedRandomVariableWithZeroMean ?

3. Jun 21, 2010

### MichaelEber

Well I guess that is what I mean. So what is the formula for that?

4. Jun 21, 2010

### CRGreathouse

The Boxâ€“Muller transform is a good way. But you're going to have to decide what standard deviation to use, and that depends on your application.

5. Jun 21, 2010

### EnumaElish

Generally speaking, you need to apply the inverse-normal (inverse Gaussian) transformation to a random variable between 0 and 1; one way is to use the algorithm CRGreathouse suggested.

6. Jun 21, 2010

### MichaelEber

Thanks for the input. Looking at the Box Muller transform, it is aimed at creating an x,y point in a two dimensional space. Since I was only interested in generating points along the x-axis I used the s1 part of the transform.

p.Y = p'.Y + (Math.Sqrt( -2 * Math.Log( rand.NextDouble( ) ) ) * Math.Cos( 2 * Math.PI * rand.NextDouble( ) )) - .5;

where each rand.NextDouble() supplies the random x1 and y1 from the evenly distributed range of points between 0 and 1.

plugged it into the formula and will begin testing soon to see how it goes.

Thanks.

7. Jun 21, 2010

### CRGreathouse

The s2 is just another random normal variable. You get two for the price of one. If speed is an issue, generate them two at a time; if not, the formula you have works.