I have a simple JavaScript that builds a random string by choosing "randomly"* from several lists of other strings. When run the script repeatedly I notice a lot of repetition and I'm trying to understand why. I understand that there is no such thing as truly random in this context. But the repetition I'm seeing is not subtle. My lists have 20-30 items each and I frequently see the same string appear two and three times in a row.
Here is the relevant code for how strings are selected from individual lists.
function(list) {
return list[Math.floor(Math.random()*list.length)];
}
The script calls this function several times in a row, passing different lists as parameters.
Is this a problem with my code? Or maybe something is getting cached?
(NOTE: This is not for security! Never do something like this as a substitute for proper encryption)