lundi 22 juin 2020

How to randomly extract a value N time in Python?

In order to program a TMS experiment, I need to randomly extract a number from a list of three values, each of one for 8 times. So I will have 24 trials, 8 of which with myvar = 1, 8 with myvar=2 and 8 with myvar=3. But after I run the experiment, the output shows that the three values were picked non-equally. How can I fix it?

My code is:

global io #TMS settings
trigger = 255
port = 0x378

lst = (1,2,3)
import random
x = random.choices(lst,k=1)
myvar = x

try:
    self.sleep(myvar)
    io.DlPortWritePortUchar(port, trigger)
    self.sleep(1)
    io.DlPortWritePortUchar(port, 0)
except:
    print('Failed to send trigger!')



Aucun commentaire:

Enregistrer un commentaire