If I generate a number from 1 to 100, there is an equal chance to hit any number, but how do I get an exact % chance

204 Views Asked by At

I am creating a game, and I feel like I am going about the random generation of a number wrong. I have a set plan that the user has a 5% chance to win prize A, and a 10% chance to win prize B. 40% to win prize C, exc.

With that said, a random number is generated from 1-100 that lets me know what prize the person will be winning before they even know. An example would be, if the random number generated was 14. My logic tells me there was a 1/100 chance of hitting 14 just like there is a 1/100 chance of generating any number between 1-100.

What I would like to do is be able to have a realistic 5% chance of winning something, and a realistic %10 chance of winning something, and a realistic %40 chance of winning something without it feeling like really, every chance is 1% chance.

1

There are 1 best solutions below

0
On

You can just used buckets. If you generate a 1, 2, 3, 4, or 5 they get prize A. If you generate a 6, 7, 8, 9, 10, 11, 12, 13, 14, or 15 they get prize B. Etc.