//Array to get non repetitive random elements from
var colors = ["Blue", "Red", "Green" , "Yellow", "Orange", "Gray"];
var colorsindx = []; //Indexes (to shuffle)
var randomcolors = []; //Shuffled Array
//init indexes (or push colors.length if adding elements to colors)
for (i=0; i < colors.length; i++) colorsindx.push(i);
//get unique random element and add it to shuffled Array
for (i=0;i < colors.length; i++) {
var rr = Math.floor(Math.random() * (colors.length - i));
var pickedcolor = colors[colorsindx[rr]]; //unique random element
colorsindx.splice(rr,1); //remove picked item index
randomcolors.push(pickedcolor); //push to Shuffled Array
}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This works...
//Array to get non repetitive random elements from
var colors = ["Blue", "Red", "Green" , "Yellow", "Orange", "Gray"];
var colorsindx = []; //Indexes (to shuffle)
var randomcolors = []; //Shuffled Array
//init indexes (or push colors.length if adding elements to colors)
for (i=0; i < colors.length; i++) colorsindx.push(i);
//get unique random element and add it to shuffled Array
for (i=0;i < colors.length; i++) {
var rr = Math.floor(Math.random() * (colors.length - i));
var pickedcolor = colors[colorsindx[rr]]; //unique random element
colorsindx.splice(rr,1); //remove picked item index
randomcolors.push(pickedcolor); //push to Shuffled Array
}