Array processing function

[EDITED]

my version from scudly


float[] arr;
int amt = 40;

void setup() {
  size( 640, 480 );
  arr = coord();
}

void draw() {
  background(0);

  if (frameCount % amt == 0) {
    arr = coord();
    amt = int(random(1, 100));
  }

  for ( int i=0; i<20; i++ )
    ellipse(arr[i], height/2, 20, 20);
}

// ------------------------------------------------

float[] coord() {

  float[] arrResult = new float[20];

  for (int i=0; i<20; i++) {
    arrResult[i] = random(width);
  }

  return arrResult;
}

Your question about for-loops

not sure if I understand you here.

remember that the screen is not updated throughout (not inside the for-loops) but only at the end of draw(). Therefore, your nested for loop would not show what you expect.
Instead the approach by scudly is correct: it uses the fact that draw() loops automatically and that it updates the screen at its end. The array gets updated coord( arr ); (“pull several different random arrays from the same function”).
Essentially scudly’s solution is equivalent to your nested for loop, except that the outer for loop is replaced by draw() itself, which loops automatically.

Chrisir