oTree Forum >

Random Round for payment in PG experiment

#1 by sakib_anwar

Hi all,

I have a related question to the question here (https://www.otreehub.com/forum/88/). 
I am running public goods experiment. I want to random round for payment. When I adopt the mentioned in that, my random_round is different for every player.
How do I get the same random round for every player?

My code is below:
class Results(Page):
    def before_next_page(player: Player, timeout_happened):
        import random

        participant = player.participant

        # if it's the last round
        if player.round_number == C.NUM_ROUNDS:
            random_round = random.randint(1, C.NUM_ROUNDS)
            participant.selected_round = random_round
            # player_in_selected_round = player.in_round(random_round)
            # player.payoff = C.ENDOWMENT - player_in_selected_round.give_amount
            player_in_selected_round = player.in_round(random_round)
            participant.payoff = player_in_selected_round.payoff

class FinalResults(Page):
    body_text='You finished the experiment'
    def vars_for_template(player):
        participant = player.participant
        # random_round=random.randint(1, C.NUM_ROUNDS)
        return dict (

    def is_displayed(player):
        return player.round_number==C.NUM_ROUNDS

Write a reply

Set forum username