Millisecond Forums

Random number generator won't accurately save to data

https://forums.millisecond.com/Topic9775.aspx

By crannie - 2/25/2013

Hi all,


I have a problem with my script. I have set a random number to be generated in order to be used as a cognitive load manipulation. So at the start of the experiment, participants observe a random 3 digit number, complete a number of set tasks and at the end of the experiment they are asked to recall the 3 digit number that was shown at the beginning.


The problem is however, that when the data is saved, the 3 digit number shown in the data log is different to the 3 digit number that is actually displayed to participants (e.g. participants see "324" but the data log records "457").


What is causing this problem and how do I fix it?


Thanks!



The relevant script sections are shown below:









<data>


/file =
"StroopWithControlKeyboard_raw.iqdat"


/separatefiles = true


/ columns = [date time subject blockcode
trialcode stimulusitem stimulusitem stimulusitem trialnum latency response
correct expressions.unrelatedlatency expressions.targetlatency expressions.unrelatedcorrect
expressions.targetcorrect]


</data>






<text numberload>

/ items = ("<%round(rand(100, 999))%>")

/ position = (50%, 50%)

/ fontstyle = ("Arial", 3%, false, false, false, false, 5, 0)

/ txcolor = darkblue

</text>




<text numberreminder>

/ items = ("Please remember this number until we ask you to type it in")

/ position = (50%, 30%)

/ fontstyle = ("Arial", 3%, false, false, false, false, 5, 0)

/ txcolor = darkgray

/ erase = false

</text>




<trial numprompt>

/ pretrialpause = 1000

/ stimulustimes = [1=numberreminder; 2000=numberload]

/ recorddata = true

/ timeout = 5000

</trial>




<block block5>

/ trials = [1=numprompt]

</block>




<expt>

/ blocks = [1=block5]

</expt>







By Dave - 2/25/2013

What is causing this problem and how do I fix it?


The problem is that you are generating the random number inline. Each time the respective <text> element is queried, a new random number will be generated. The <text> element is queried *twice*, once when it's displayed on screen and second time when it's written to the data file. Thus the discrepancy. The solution is to store your random number in a <values> entry instead of using an inline expression.


Cf. http://www.millisecond.com/forums/Topic6753.aspx#6753

By crannie - 2/26/2013

thanks for your help!!