[solved] How do I create a random RSVP stream of digits WITH replacement
Hi,
I am trying to program an attentional blink experiment where the RSVP stream is a 20 item stream of digits randomly sampled from digits 0-9. There is also the constraint that each selected digit is not one of the two preceding items in the stream.
The function random.sample obviously does not work since the sample is larger than the population. I have been trying to find another function to use that samples randomly from a population with replacement. Does anyone have a solution for this?
Best regards,
Ólafía
Comments
Hi Olafia,
I suggest following:
1) Create a list with the numbers from 0 to 9
2) Create two placeholder variables to store the two preceding values and assign an arbitrary value to them.
3) use
random.choiceto pull a random number from your list repeatedly in awhileloop and add these values to a new list, that contains all stimuli of your stream, unless they match any of the placeholders and update your placeholder variables.4) Et voila!
Here everything in (almost) python code:
Does this make sense?
Eduard
Thank you Eduard!! This works!