#1 by tae_yn
Hi, I would like to assign 11 people to A, B, and C group. However, I would like to assign 5 people to A, 5 people to B, and 1 person to C group. I tried the following code from the tutorial, yet I think the random.choice involves replacement of elements. what could be the solution? # def creating_session(self): # for player in self.get_players(): # player.type = random.choice(['A', 'A', 'A', 'A', 'A', # 'B', 'B', 'B', 'B', 'B', 'C']) # print('set player.type to', player.type)
#2
by
ccrabbe
Hi tae_yn - If you assign that array to a variable name like 'typelist' and then set player.type to an element chosen randomly with random.choice, and then *remove* that chosen element from typelist, then you will be choosing without replacement. so: typelist = [A,A,A,...] for p in subsession.get_players(): p.type = random.choice(typelist) typelist.remove(p.type) ... that should do it. Thanks, --Chris
#3 by tae_yn
Thank you!