array trouble (newbie)
in
Programming Questions
•
2 years ago
Hi, I'm making an array of six elements printing them in random order, and I just need each element not repeating right after it's own occurrence. I've been trying booleans and looks like there should be a simple solution, but I still can't figure the combination.
I'll appreciate any reference -or the answer if its easier- that lets me know how I tell the program "next time, choose one of the rest, not what you've just printed"?
Second question: The code resulted in a random that is conditioned to the first element of the array, so the series tends to have many "zeros", and very occasionally -and at the end- one "five". Why is that happening?
(This code is an abstraction, just to be clear).
- String [] string = {
- "zero", "one", "two", "three", "four", "five"
- };
- void draw () {
- for (int i = 0; i <= string.length; i++) {
- print (string [int (random (i))] + ", ");
- delay (500);
- }
- }
- if (millis () >= 20000) {
- print ("exit.");
- exit();
- }
- }
Thanks so much for your help.
Marcelo
1