# Straightening out the Gaussian random distribution

Any time you sum up a bunch of variables or use the weighted sum the Gaussian distribution tends to appear. You may want to convert that into the uniform distribution for various applications. The standard method is to use the Gaussian Cumulative Distribution Function (CDF.)
However it seems you can use atan2 to do the conversion if you accept using 2 numbers at a time. Don’t ask me the math of that. Lol. Intuition. Also there is a simpler function that is quite close.

``````float[] data=new float;
void setup(){
size(900,300);
background(0);
for(int i=0;i<50000;i++){
data[i]=randomGaussian();
}
for(int i=0;i<50000;i+=2){
int x=150+int(40f*data[i]);
int y=150+int(40f*data[i+1]);
set(x,y,color(255,230,0));
}

for(int i=0;i<50000;i+=4){
int x=450+int(40f*atan2(data[i],data[i+1]));
int y=150+int(40f*atan2(data[i+2],data[i+3]));
set(x,y,color(0,230,255));
}

for(int i=0;i<50000;i+=4){
int x=750+int(130f*abDiv(data[i],data[i+1]));
int y=150+int(130f*abDiv(data[i+2],data[i+3]));
set(x,y,color(127,230,127));
}

}

float abDiv(float a, float b){
int ai=Float.floatToRawIntBits(a);
int bi=Float.floatToRawIntBits(b);
float aa=Float.intBitsToFloat(ai&0x7fffffff);
float ab=Float.intBitsToFloat(bi&0x7fffffff);
if(aa<ab) return a/(ab+1e-30);
return b/(aa+1e-30);
}

``````