lundi 18 septembre 2017

Java - weighted random number [duplicate]

This question already has an answer here:

I am creating a program that will generate a number between 1 to 3 representing 3 states: California, Nevada, Utah (respectively). I want to somehow add weight to these three numbers. California should have a 67% chance, Nevada with 20%, and Utah with 13%. How can I add these weights to a random number generator that would increase the chance of 1 (CA) being the result, as opposed to 3 (UT), which has the smallest weight out of the 3 (13%). Any tips/help will be appreciated.




Aucun commentaire:

Enregistrer un commentaire