erubiel:
Thank you PaulVdB I've been looking for this for a long time.
I'm happy it is useful to you. Please inform "el_supremo" about your happiness and my (what he called "messy") code !
The array has 144 elements now. (I use it for programming a WS2812 LED string of 144 Led's)
as an extension here's the code I made if you need a new (scrambled) array.
/*
This sketch randomizes the elements of an arry a[] and puts 'em in a new one b[].
It will NEVER pick the same element twice !
There's one element more at the end (0) than we need.
ENJOY ! (and let me know if you find errors and/or improvements !)
*/
int f;
int i;
int n;
int p;
int x;
void setup()
{
randomSeed(analogRead(0));
Serial.begin(115200);
Serial.println();
}
void loop()
{
int a[145] = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ,
10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 ,
20 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 ,
30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 ,
40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 , 49 ,
50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 ,
60 , 61 , 62 , 63 , 64 , 65 , 66 , 67 , 68 , 69 ,
70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 ,
80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 ,
90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 ,
100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 ,
110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 ,
120 , 121 , 122 , 123 , 124 , 125 , 126 , 127 , 128 , 129 ,
130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 ,
140 , 141 , 142 , 143, 0
};
int b[144] = {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ,
10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 ,
20 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 ,
30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 ,
40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 , 49 ,
50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 ,
60 , 61 , 62 , 63 , 64 , 65 , 66 , 67 , 68 , 69 ,
70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 ,
80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 ,
90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 ,
100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 ,
110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 ,
120 , 121 , 122 , 123 , 124 , 125 , 126 , 127 , 128 , 129 ,
130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 ,
140 , 141 , 142 , 143
};
for (n = 144; n > -1; n--) // here we pick random elements in the array until we got 'em all
{
x = random(n);
p = a[x];
b[n - 1] = p;
for (i = x; x < n; x++) // here we shift all elements (who come AFTER the chosen one) in the array one place to the left
{
a[x] = a[x + 1];
}
}
for (f = 0; f < 144; f++)
{
Serial.print(b[f]);
Serial.print(" ");
// delay(5);
}
Serial.println();
//delay(20);
}