setting a probablity for an action or game event

Viewed 15

i want to set Win probability of 70% and a lose probability of 30 % for a specific game playing event or action how do i attain this in python any library for this to make this task easier

1 Answers

One way coud be using a uniformly distributed random number between {0-1} and assigning win when the value is <= 0.7 and lose the rest of cases:

import random
random_number = random.random()
if random_number <= 0.7:
    print('Win')
else:
    print('Lose')
Related