can someone help me with this last bit.

int numbers = 10;
float [] x = new float[numbers];
float f = 0.0;
float avg = 0.0;

void setup() {
  populate();
}
void draw() {
}
void populate() {
    for (int i = 0; i < numbers; i++) {
    x[i] = int(random (0,100));
    println(x[i]);
    f += x[i];
    }
    avg = f/10.0;
}
void keyPressed() {
  if (key == 'r') {
    populate();
  }
  if (key == 'a') {
      println(avg);
  }
}
float jdd() {
  for (int i = 0; i < numbers; i++) {
    float r = int(random(x[i]));
  }
  return(0);
}
void mousePressed() {
  println(jdd);
}

what im trying to is define a function that returns (but does not print or otherwise display) a random element of this array. Using the previously mentioned function, use println() within a mousePressed() event definition to have a random element (returned from the function you define in this step) print to the console on every mouse click.

Tagged:

Answers

Sign In or Register to comment.