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?
2 odpowiedzi
+ 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);
}
0
I'll give it a shot later, thanks!