Issues with numbers choices

Hello,
we are three french students who use psychopy for the first time. We would like to create several sequences of characters in which we have 3 to 5 letters and one number between 0 to 9. But we would like to have a different number between each sequence. We have succeed to create the sequences of characters but we got the same number several times. How can we manage this ?

Hey @Noemie_P,

Can you share your code so we can take a look?

Yes sure !
The routine “chiffre” is the routine we used to display numbers. It is mentioned in lines 203 and 525. expérience1.py (17.0 KB)

If you don’t want your numbers to be repeated, maybe you can force your text_2 to pick a unique number in the sequence 0-9. Because your sequence is short, randrange is likely to pick the same number more than once.

You can create a vector with your sequence and then pop the ones you already used every loop:

# outside loop - vector preparation:
set_of_numbers = []
for k in range(0,10): 
	set_of_numbers.append(k)
random.shuffle(set_of_numbers)

# inside loop, every iteration:
text_2.setText(set_of_numbers.pop(0))

This will destroy your set_of_numbers variable, but it will make sure no number is repeated.

It’s working, thanks a lot !

1 Like