วันศุกร์ที่ 3 ตุลาคม พ.ศ. 2557

Write A Function To Create Random Values In An Array 2



 (with parameter to specify whether duplicate values are allowed)

int [] value  = new int [5];
void setup () { 
  size (130, 50);
  background (0, 0, 204);
  Random_value (10, 50);
}
void Random_value (int start, int end) {
  int space = 15;
  text ("{", 10, 30);
  for (int i = 0; i<value.length; i++) {
    value [i] = int (random (start, end));
  }
  for (int i = 0; i<value.length; i++) {
    if (i < value.length) {
      text (value[i], space, 30);
      space = space + 20;
      if (i<value.length-1) {
        text (",", space-5, 30);
      }
    }
    if (i == value.length-1) {
      text ("}", 110, 30);
    }
  }

}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น