Randomize questions order / lottery

325 views
Skip to first unread message

vincent teixeira

unread,
Aug 26, 2021, 7:53:39 AM8/26/21
to oTree help & discussion

Hi everyone,

I have some problems to code my app and I hope that somebody can give me leads to follow.

Using Ellserberg urns I have different treatments which are risk and ambiguity.

When the subject face a decision, if it’s a risk situation, he knows that there is 30 black balls 20 white and 50 yellow. 

But when it’s ambiguity he knows that there is between 20 and 40 black balls, between 40 and 60 white and between 30 and 70 yellow.

I want to mix risk and ambiguity in the same app to randomize the questions order.

My problems are :

  • The list for the risky situations is shorter, so I can not use the same html file for both treatments. For example my list for the situation is (30,20,50) when it’s (20,40,40,60,30,70). I did cheat a bit and use text in the second list to fix the HTML but I think it won’t work if I want to implement payments. (attached screenshots )
  • For every decision that the player will take there may be a lotery to be played.  I could not fine how to make a lottery draw in o-tree. Maybe you can help me with it.


For the payement, I will draw one decision that the player made. Then, for this decision I will draw a row of the table decision (attached to the mail). If for this row he prefers to draw a ball then we will draw a ball. If he prefer 20€ with a probability 0,3 then we will do a lottery with 30% chance of wining. 


I hope that my explanations are clear.

Thank you!

Vincent

Capture d’écran 2021-08-26 à 13.49.07.png
Capture d’écran 2021-08-25 à 17.24.10.png
Capture d’écran 2021-08-26 à 13.48.45.png

BonnEconLab

unread,
Aug 27, 2021, 2:25:20 PM8/27/21
to oTree help & discussion
Hi Vincent,

Regarding your first bullet point, your workaround via including empty strings seems to works fine, so why change it? I wouldn’t call this “cheating.” I don’t understand what you mean by “I think it won’t work if I want to implement payments.”

Regarding the second bullet point, including something along the following lines in your __init__.py should do the job. Include

from random import randrange

at the top of the file. In class Player(BasePlayer): include something like

    random_draw = randint(1, 100)
    num_black_balls = 20
    if random_draw <= num_black_balls:
        points = 20
    else:
        points = 0

The variable num_black_balls will be different from round to round, I guess.

Is this what you were asking for or did I misinterpret your question?

Best,

Holger

vincent teixeira

unread,
Sep 2, 2021, 8:28:54 AM9/2/21
to oTree help & discussion
Here is the solution that Holger gave me. It works perfectly. 

Hi Vincent,

I would probably do something like the following: I would generate the string depending on the number of balls as follows in Python and send over the entire string via vars_for_template:

For the choices under risk:

num_balls = [30, 20, 50]

For the choices under ambiguity:

num_balls = [20, 40, 10, 30, 30, 70]

Then generate the string like this:

if len(num_balls) == 3:
   urn_string = "There are " + str(num_balls[0]) + " black, " + str(num_balls[1]) + " blue, and " \
   + str(num_balls[2]) + " red balls in the urn."
else:
   urn_string = "There are between " + str(num_balls[0]) + " and " + str(num_balls[1]) \
   + " black, between " + str(num_balls[2]) + " and " + str(num_balls[3]) + " blue, and between " \
   + str(num_balls[4]) + " and " + str(num_balls[5]) + " red balls in the urn."

Determining the random payoff can then be done based on num_balls alone.

If this works solution for you, may I or can you please post this also to the list so that others can benefit from it, too?

Best,

Holger



On 2021-09-02, at 09:19, wrote:


Hi Holger,

Sorry for the delay of response, I don't know why but I just get your answer today.

Thank you so much for your answer. You perfectly understood my question.
Regarding the ''I think it won't work if I want to implement payments", it's because I will have to draw a lottery depending of the current question in my list. But if there is extra letter like "[0;" I'm not sure that I can randomly draw it. I will try to implement it today.

Best wishes,

Vincent

Le vendredi 27 août 2021 à 20:25:20 UTC+2a écrit :
Hi Vincent,

Regarding your first bullet point, your workaround via including empty strings seems to works fine, so why change it? I wouldn’t call this “cheating.” I don’t understand what you mean by “I think it won’t work if I want to implement payments.”

Regarding the second bullet point, including something along the following lines in your __init__.py should do the job. Include

from random import randrange

at the top of the file. In class Player(BasePlayer): include something like

    random_draw = randint(1, 100)
    num_black_balls = 20
    if random_draw <= num_black_balls:
        points = 20
    else:
        points = 0

The variable num_black_balls will be different from round to round, I guess.

Is this what you were asking for or did I misinterpret your question?

Best,

Holger

Reply all
Reply to author
Forward
0 new messages