#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):
@staticmethod
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'
@staticmethod
def vars_for_template(player):
participant = player.participant
# random_round=random.randint(1, C.NUM_ROUNDS)
return dict (
my_cont=player.in_round(participant.selected_round).contribution,
tc=player.in_round(participant.selected_round).group.total_contribution,
mypayoff=player.in_round(participant.selected_round).payoff,
payoff_round=participant.selected_round,
earnings=participant.payoff_plus_participation_fee()
)
def is_displayed(player):
return player.round_number==C.NUM_ROUNDS