+ 2

How to create random with unequal possibility?

for example random from a to z

3rd Mar 2017, 9:28 PM
Geovim
Geovim - avatar
5 Réponses
+ 13
Maybe you could have a string like "aaaaaaaaaaaabbbbc..." a has 60%, b has 20% and c has 5%...
3rd Mar 2017, 10:52 PM
Jafca
Jafca - avatar
+ 3
from random import randint x = randint(1, 100) letter = 'z' if x < 61: letter = 'a' elif 60 < x < 81: letter = 'b' elif 80 < x < 86: letter = 'c' ....... etc
4th Mar 2017, 12:42 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
import string import random # or string.ascii_letters random.choice(string.letters)
3rd Mar 2017, 10:06 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
i mean for example the possibility of choosing be: a=60% , b=20% , c=5% , ...(unequal possibility)
3rd Mar 2017, 10:12 PM
Geovim
Geovim - avatar
0
for example we have three char (a,b,c) , i want to select randomly one of them with contigency a=60%, b=10% , c=30%.
4th Mar 2017, 10:18 AM
Geovim
Geovim - avatar