|
Post by regina on Jun 6, 2020 17:44:52 GMT
Hi,
I want to use the set function in a task in order to randomly choose a bitmap stimulus:
set $my_target random 1 10
However, I want to present each stimulus only once. Is it possible to add a "random without replacement" command to the set function? I tried to do it using a while loop but I could not find a way to tell the computer which values it has already used. I tried to solve this using the feedback function but this does not work in tasks.
(I know that random without replacement is possible with using tables, but I cannot use a table here for a different reason).
Any help is appreciated.
Thank you!
|
|
|
Post by PsyToolkit on Jun 6, 2020 19:23:58 GMT
that is not possible
|
|
|
Post by JR on Jun 30, 2020 8:29:38 GMT
A rather painful way to do this would be to have 10 global variables that you set to 0 initially, which you set to 1 when they have been chosen. Each time you draw a random number, do it in a while loop and check whether that value has been "taken" already by checking its global variable. If it has, force a re-sample. Global variables are needed if you're trying to avoid re-use between trials, but if repetition just needs to be avoided within a trial, you can use local variables ($) that are initialized at the start of the trial. Something like this:
# imagine you've already set up the 10 "taken" variables with the values of 0 set $done_choosing 0 while $done_choosing == 0 set $my_target random 1 10 if $my_target == 1 && &one_taken == 0 # if 1 is available, we can keep the sample and exit the loop set $done_choosing 1 set &one_taken 1 # set to 1 so we don't choose this number again fi if $my_target == 2 && &two_taken == 0 set $done_choosing 1 set &two_taken 1 fi # and so on... handling three through nine... if $my_target == 10 && &ten_taken == 0 set $done_choosing 1 set &ten_taken 10 fi while-end
|
|