I'm confused as to why the below produces the same pairs of values for race and gender in each iteration through the for loop. I would imagine the initial seed value for random() (not explicitly declared in my code) is taken in the first iteration and then the loop proceeds to the next value in the random sequence based on the initial seed, but it appears that is not the case. Instead, it appears to use the same seed/value for each iteration, leading to identical values of race and gender across each iteration.
Minimal working example:
// Two arrays
var race = ["B","W"];
var gender = ["F", "M"];
for (i = 0; i < 6; i++) {
var race = race[Math.floor(Math.random()*race.length)];
var gender = gender[Math.floor(Math.random()*gender.length)];
document.write(race)
document.write(gender)
}
// Example result: BMBMBMBMBMBM (BM repeated 6 times)
Is there someway of looping through using independently drawn values instead of producing identical values for each loop iteration? Apparently this has been answered in C++ and there are many questions on Javascript seeding, but not this.