I recently ran and tested the following code to execute on a webpage. For each person who visits my webpage, this code is supposed to run before they view the page in order to randomly funnel 50% of them into seeing a different webpage. The code I produced (see below), based on my understanding (and testing) generates a random number between 1 and 10. After compiling it and running it in 1000 times, I confirmed that 1, 2, 3, 4, 5 are generated approximately 50% of the time and 6, 7, 8, 9, 10 are generated 50%. Thus, I would expect that, based on my code, anyone with a 1, 2, 3, 4, or 5 would meet the criteria of the if statement.
var rando = Math.floor((Math.random() * 10) + 1);
if(rando < 6){
//execute unrelated jquery code here to modify webpage
}
Unfortunately, execution on the webpage did not work as planned. Out of 250 unique visitors to my webpage, 100 triggered the if statement, and 150 did not. While this could obviously be the result of random chance, it is probably more likely the source of some error I am missing. As stated above, I tested this code and saw that it was generating the distribution I was expecting I researched this specific issue on stack exchange, and while there appears to be a bias in the random number generator in some instances, I do not think my code runs into that issue. Any help or insight would be greatly appreciated!