samedi 22 avril 2017

How to get a random generated item from an array with chances? | javascript

For example: There are four items in an array. I want to get one random, like this:

array items = [
    "bike"    //40% chance to select
    "car"     //30% chance to select
    "boat"    //15% chance to select
    "train"   //10% chance to select
    "plane"   //5%  chance to select
]




Aucun commentaire:

Enregistrer un commentaire