GSDP:GAM100/CProcessing/randomGaussian()

From Inside
Jump to: navigation, search

randomGaussian()

Description

Returns a normally distributed random value where the median is 0 and the standard deviation is 1.

Example

int gaussianData[100] = { 0 };
void init() 
{
    // Build 100 rectangle heights using randomGaussian to increment different heights
    for (int i = 0; i < 100000; ++i)
    {
        double gaus = randomGaussian() * 20 + 50;
        if (0 <= gaus && gaus < 100)
        {
            ++gaussianData[(int)gaus];
        }
    }

    // Set the draw mode
    rectMode(CENTER);
    noStroke();

    // Draw each rectangle with the heights created from the random gaussian values
    int index = 0;
    for (int x = 0; x < canvasWidth; x += canvasWidth / 100)
    {
        fill(color(255, 180, 180, alpha1));
        rect((float)x + (canvasWidth / 200), canvasHeight / 2.0f, (float)canvasWidth / 100.0f, (float)gaussianData[index++] / 5.0f);
    }
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>