mercredi 28 avril 2021

Math.random() in Javascipt giving quite non-random looking distribution

I'm running a study which redirects participants to one of 8 random websites using the below piece of javascript (on an otherwise blank HTML page).

What's odd is the distribution of participants to each site. I have about 64 participants so far and I know that true randomness does not mean there should be 8 visitors to each site. However, one of the sites only has had a single redirect (site number 5) while another one has had 19 (site number 1). The others are all close to 8 visits each.

I just wanted to check that I haven't made any silly mistakes/assumptions with such a simple code. I can't think of any reason why it would be much more likely to generate a "1" and much less likely to generate a "5".

Is it just the case that this is the luck of the draw with random number generation and that one can end up with some sites being visited 19 more times that others while sample size is low and there are 8 possibilities?

Any opinions would be really appreciated.

<script type="text/javascript">

function randomlinks(){
        var myrandom=Math.floor(Math.random()*8)
        var links=new Array()
        links[0]="[website0 name here]"
        links[1]="[website1]"
        links[2]="[website2]"
        links[3]="[website3]"
        links[4]="[website4]"
        links[5]="[website5]"
        links[6]="[website6]"
        links[7]="[website7]"
     
        window.location=links[myrandom]
        }
    
    randomlinks();
</script>



Aucun commentaire:

Enregistrer un commentaire