0

When should I prevent duplicates in random variables?

So I'm trying to make a bit of a joke about my school's schedule being random, and I want to make a randomizer for it. I want a list of five variables in the html side, all of which are unique outputs of random variables generated in javascript. Each value would be 1 of 7 (A, B, C, D, E, F, G, H).To prevent duplicate variable values, should I have some sort of system that randomized each variable until it's unique, or should I find some sort of convoluted workaround that applies to the randomization itself?

7th Dec 2017, 4:19 PM
Sheev
Sheev - avatar
2 Answers
+ 1
Try this: function joke() { var values = ["A", "B", "C", "D", "E", "F", "G", "H"], randomSchedule = values[Math.floor(Math.random() * values.length)]; // do something with the selected value alert(randomSchedule); }
7th Dec 2017, 9:27 PM
Elias Papachristos
Elias Papachristos - avatar
0
I'll give it a shot later, thanks!
8th Dec 2017, 3:04 AM
Sheev
Sheev - avatar