lundi 9 octobre 2017

How to generate a random number in Excel VBA

I wanted to write a function generate some numbers which represent

2 = White, 3 = Red, 4 = Green, 5 = Blue, 6 = Yellow

I know that if it is equal probability, then I can write

GenerateColor = Int(Rnd() * 5) + 2

However, I want to generate white half of the time and share the other half with the remaining 4 colors, how can I do? (It means 50% probability is white, 50% of probability is remaining 4 colors.)




Aucun commentaire:

Enregistrer un commentaire