Name

randomGaussian()

Description

Returns a float from a random series of numbers having a mean of 0 and standard deviation of 1. Each time the randomGaussian() function is called, it returns a number fitting a Gaussian, or normal, distribution. There is theoretically no minimum or maximum value that randomGaussian() might return. Rather, there is just a very low probability that values far from the mean will be returned; and a higher probability that numbers near the mean will be returned.

Examples

  • size(400, 400);
    for (int y = 0; y < 400; y++) {
      float x = randomGaussian() * 60;
      line(200, y, 200 + x, y);
    }
    Image output for example 1
  • float[] distribution = new float[360];
    
    void setup() {
      size(400, 400);
      for (int i = 0; i < distribution.length; i++) {
        distribution[i] = int(randomGaussian() * 60);
      }
    }
    
    void draw() {
      background(204);
      
      translate(width/2, width/2);
    
      for (int i = 0; i < distribution.length; i++) {
        rotate(TWO_PI/distribution.length);
        stroke(0);
        float dist = abs(distribution[i]);
        line(0, 0, dist, 0);
      }
    }
    Image output for example 2

Syntax

  • randomGaussian()

Return

  • float
Creative Commons License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.