In javascript, I am little bit confused that how to get the actual and accurate probability of shuffling an object in an array. For example
var numberOfOrder=[
{
id:1
},
{
id:2
},
{
id:3
}
]
From above example The above object can be manipulated in 6 ways By finding the factorial numberOfOrder.length;
But what is the actual way to shuffle that object in an array.
My Try
function newShuffle(value) {
for(var i = value.length-1;i >=0; i--){
var randomIndex = Math.floor(Math.random()*(i+1));
var itemAtIndex = value[randomIndex];
value[randomIndex] = value[i];
value[i] = itemAtIndex
}
return value
}
But the above function won't return accurate value if I run that function 6 times it returning Duplicate Values
What is the correct function to do it