Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] How do I create a random RSVP stream of digits WITH replacement

edited November 2015 in OpenSesame

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

  • edited 11:52AM

    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.choice to pull a random number from your list repeatedly in a whileloop 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:

    import random
    numbers = list(range(9))
    target_list = []
    prev1 = 10
    prev2 = 10
    
    while len(target_list) < targeted_length:
        no = random.choice(numbers)
        if no not in [prev1,prev2]:
            target_list.append(no)
            prev2 = prev1
            prev1 = no
    

    Does this make sense?

    Eduard

    Buy Me A Coffee

  • edited November 2015

    Thank you Eduard!! This works!

Sign In or Register to comment.