Is it possible to randomly generate an int value going 1-13 and not make the numbers repeat more than once during this sequence?
1 Like
I want this number to randomise the order of the quiz and be able to restart it with a different order each time @Chrisir magic?
Yes. There are many ways, but one easy built-in way is to make an IntList, then call shuffle().
2 Likes
IntList inventory;
void setup() {
size(200, 200);
inventory = new IntList();
inventory.append(1);
inventory.append(2);
inventory.append(3);
inventory.append(4);
inventory.append(5);
inventory.append(6);
println(inventory);
inventory.shuffle();
println(inventory);
int a = inventory.get(2);
println(a);
}
1 Like
final IntList sequence = IntList.fromRange(1, 14);
println(sequence);//IntList size=13 [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
sequence.shuffle(this);
println(sequence);
exit();
3 Likes