2.2 Random vs. Noise

Here are two examples that show the difference between using random values and the noise function in processing. Random will return a unique number each time it is run. Noise will return a value based on a Perlin noise map. In these examples we are creating a series of vertical lines whose height is based on random and noise based values.

void setup(){
  size(1200,500);
  noLoop();
}

void draw(){
  background(0);
  stroke(255);
  strokeWeight(3);
  float noisepos = 0;
  for(int i = 0; i < width/3; i++){
    float x1 = i * 3;
    float y1 = height/2;
    float x2 = i * 3;
    float y2 = height/2 - random(200);
    line(x1,y1,x2,y2);
    noisepos = noisepos + 0.01;
  } 
}

void setup(){
  size(1200,500);
  noLoop();
}

void draw(){
  background(0);
  stroke(255);
  strokeWeight(3);
  float noisepos = 0;
  for(int i = 0; i < width/3; i++){
    float x1 = i * 3;
    float y1 = height/2;
    float x2 = i * 3;
    float y2 = height/2 - noise(noisepos) * 200;
    line(x1,y1,x2,y2);
    noisepos = noisepos + 0.01;
  } 
}