Randomize two stimuli
I desingned an experiment with the visual presenation of 2 stimuli. However, I need to randomize these 2 visual stimuli so that they won't appear more than twice. Here is my script which i made using the help from samples.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' The following script will make sure that the same type of stimulus is 'not presented on consecutive trials. The randomization process 'continues until this criterion is 'met.'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Counter variable. nCount is used in For...Next loops. Dim nCount As Integer
'This variable will be True as long as the no repeats criterion has been met. Dim boolNoRepeats As Boolean
'This variable will be false as long as we do not need to restart randomization Dim boolRestartRandom As Boolean boolRestartRandom = False
'Create variable to hold the position to start re-randomizing Dim nStartPos As Integer nStartPos = 1
'Create variable for the number of retries allowed before quitting Dim nRetry As Long Const MAX_RETRY = 200
'These debug statements show how quickly the randomization process works. Debug.Print "Begin = " & Clock.Read
'Randomize the array and check for repeated types in consecutive slots. If 'any repeated types are found, set the criterion to False. Do
boolNoRepeats = True
'Reduce nStartPos by 1 so that we check the repeats starting before the restart position 'Otherwise nStartPos and nStartPos - 1 could be the same If boolRestartRandom = True Then nStartPos = nStartPos - 1
If boolNoRepeats = False Then
'We need to retry, but let's start from the point ' the failure happened and reshuffle from there nStartPos = nCount
Debug.Print "Rerandomizing starting at " & nStartPos boolRestartRandom = True
'Increment the retry count nRetry = nRetry + 1
'Have we exceeded the number of times to retry? If nRetry > MAX_RETRY Then Debug.Print "Cannot fulfill the no repeat condition with this random seed" Debug.Assert False End If End If
Loop Until boolNoRepeats = True
Debug.Print "End = " & Clock.Read
TrialList.Reset
Please sign in to leave a comment.
Comments
0 comments