Random draw from uniform distribution

63 views
Skip to first unread message

Stefano Pagliarani

unread,
Jan 11, 2022, 5:23:52 AM1/11/22
to oTree help & discussion
Hello everyone,

I am looking for a way to code a random draw from a uniform distribution, with fixed probability. So like, in each round there is a probability p that one value from a uniform distribution is drawn and used to calculate the payoff of players. Instead, with probability (1-p) simply nothing happens.
I tried using numpy in several ways, but I get an application error.
Do you have any ideas?

Thank you in advance
Stefano

Max R. P. Grossmann

unread,
Jan 11, 2022, 5:29:58 AM1/11/22
to Stefano Pagliarani, oTree help & discussion
Hi Stefano,

Have you considered using something like

import random

p = 0.8 # probability

if random.random() < p:
# something should happen
else:
# nothing should happen

Best,

Max
Reply all
Reply to author
Forward
0 new messages