randomize array
in
Programming Questions
•
1 year ago
hey guys...im having trouble with creating a method that when passed an array randomizes the order of all the items in the
array.
- void setup() {
- int[] a = new int[3];
- for(int i=0; i<a.length; i++)
- a[i] = i+1;
- display(a); //displays 1 2 3
- randomize(a);
- display(a);
and this is what i have:
- void randomize (int[]value){
- for(int i=0;i<value.length;i++)
- value[i] = (int)random(3);
- }
- /*the second display method can display either
- ! 1 2 3 or
- ! 1 3 2 or
- ! 2 1 3 or
- ! 2 3 1 or
- ! 3 1 2 or
- ! 3 2 1
- ! */
2