Millisecond Forums

Using rand(x,y) in expressions

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

By AKrishna - 11/21/2018

Hi,

just a quick question: if I set up an expression that includes a rand(x,y) function, will the random number be picked once or will it be repicked every time the expression is called? So for example:

<expressions>
/ MyExpression = 100 + rand(-50,50)
</expressions>

<trial Tester>
/ stimulustimes = [0 = TestText]
/ validresponse = (" ")
</trial>

<text TestText>
/ items = ("Showing number <%expressions.MyExpression%>")
</text>

If trial.Tester is repeated, will there be different values for MyExpression shown? If not, are there any circumstances that might cause the expression to draw a new random number? I'm asking because the closest analogues, new elements from lists, appear to be accessed only when called via a reference to list.MyList.nextitem in an ontrialbegin/ontrialend/branch, not when referenced in a text object using <%list.MyList.nextitem%> - or at least that was my understanding.

Thanks for any help!



By AKrishna - 11/21/2018

AKrishna - Thursday, November 22, 2018
Hi,

just a quick question: if I set up an expression that includes a rand(x,y) function, will the random number be picked once or will it be repicked every time the expression is called? So for example:

<expressions>
/ MyExpression = 100 + rand(-50,50)
</expressions>

<trial Tester>
/ stimulustimes = [0 = TestText]
/ validresponse = (" ")
</trial>

<text TestText>
/ items = ("Showing number <%expressions.MyExpression%>")
</text>

If trial.Tester is repeated, will there be different values for MyExpression shown? If not, are there any circumstances that might cause the expression to draw a new random number? I'm asking because the closest analogues, new elements from lists, appear to be accessed only when called via a reference to list.MyList.nextitem in an ontrialbegin/ontrialend/branch, not when referenced in a text object using <%list.MyList.nextitem%> - or at least that was my understanding.

Thanks for any help!




...and then I realized I could just run my own example code several times.

So expressions do grab a new random number each time they are referenced. And it also turns out I was wrong: lists do grab new list elements even if the only reference to a new element in the trial is in a <text> stimulus using <%list.MyList.nextvalue%>.

So if anyone was wondering...
By Dave - 11/22/2018

AKrishna - Thursday, November 22, 2018
AKrishna - Thursday, November 22, 2018
Hi,

just a quick question: if I set up an expression that includes a rand(x,y) function, will the random number be picked once or will it be repicked every time the expression is called? So for example:

<expressions>
/ MyExpression = 100 + rand(-50,50)
</expressions>

<trial Tester>
/ stimulustimes = [0 = TestText]
/ validresponse = (" ")
</trial>

<text TestText>
/ items = ("Showing number <%expressions.MyExpression%>")
</text>

If trial.Tester is repeated, will there be different values for MyExpression shown? If not, are there any circumstances that might cause the expression to draw a new random number? I'm asking because the closest analogues, new elements from lists, appear to be accessed only when called via a reference to list.MyList.nextitem in an ontrialbegin/ontrialend/branch, not when referenced in a text object using <%list.MyList.nextitem%> - or at least that was my understanding.

Thanks for any help!




...and then I realized I could just run my own example code several times.

So expressions do grab a new random number each time they are referenced. And it also turns out I was wrong: lists do grab new list elements even if the only reference to a new element in the trial is in a <text> stimulus using <%list.MyList.nextvalue%>.

So if anyone was wondering...

Just chiming in to confirm: Yes, that's correct, an expression will (and is supposed to) return a new value every time it is called. For <list> elements, things depend on their /selectionrate setting. The default behavior is /selectionrate = trial, i.e. the list will return one item from its pool when it is used in some way in a <trial>. Subsequent references to the list during that instance of the <trial> would return the same value. If the list is set to /selectionrate = always, however, it would perform a new selection every time it is referenced during a given instance of a <trial>.