Randomize only a part of an array
in
Programming Questions
•
8 months ago
Hello everbody,
with help of the forum I've got the following code. But I would like to randomize only a part of the array. E.g. "radomarray[0-4]". How is that possible?
Thanks in advance.
- int[] randomarray = new int[10];
- void setup()
- {
- }
- void draw()
- {
- for(int i=0; i < randomarray.length; i++){
- randomarray[i]=i;
- }
- for (int i=0; i < randomarray.length; i++) {
- int temp = randomarray[i];
- int x = (int)random(0, randomarray.length);
- randomarray[i]=randomarray[x];
- randomarray[x]=temp;
- }
- println(randomarray);
- }
1