Creating a same random number for all players.

386 views
Skip to first unread message

Hyo-eun Park

unread,
Feb 17, 2022, 5:19:22 AM2/17/22
to oTree help & discussion
Hi all,

I want to create one random number and pass this number to all subjects.

Is there any simple way to do this?

I would appreciate any help or comments!

Best,
Hyoeun

Chris @ oTree

unread,
Feb 17, 2022, 5:29:35 AM2/17/22
to Hyo-eun Park, oTree help & discussion
Store it in a session field. See SESSION_FIELDS. 

Sent from my phone

On Feb 17, 2022, at 6:19 PM, Hyo-eun Park <hyoeu...@gmail.com> wrote:

Hi all,
--
You received this message because you are subscribed to the Google Groups "oTree help & discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/dc34134d-ceb6-42fa-bf83-1b0762a2ee8en%40googlegroups.com.
Message has been deleted

Chris @ oTree

unread,
Mar 2, 2022, 10:24:04 AM3/2/22
to oTree help & discussion
These future sessions are with the same participants? (As a continuation in a longitudinal study)
or with different participants?

On Wednesday, March 2, 2022 at 11:12:10 PM UTC+8 coolcam wrote:
Chris,

I have a similar question to the original post in this thread.

When I run my app for the first time, I want to 'pass' a random number to all participants in that first session. I have no problem doing this.

However, my problem is that going forward in future data collection sessions I want to hold the order of this random number constant for all remaining sessions. Is there an easy way to do this?

coolcam

coolcam

unread,
Mar 2, 2022, 1:38:06 PM3/2/22
to oTree help & discussion
Different participants.

You can imagine I'm using a real-effort task, like a letter-search task. The blocks of text that participants search through are constant across all sessions.

For example, I have XXX blocks of text [textblock-1, textblock-2 ...  textblock-XX, etc.].

The order that participants view these blocks of text is constant for all participants in all sessions across all conditions. 

The problem is that the randomly generated "search-letter" in this example, is generated when the session is created when the session is created. So, I can
hold it constant within a session, but not across sessions again with different Ps. 

The concern being that in session 1, textblock-1, participants' search letter = e

and then in session 2, textblock-1, participants' search letter = x

I'd like to get it to a point where the first time the app runs it randomly determines the sequence of randomly determined 'search letters'
^^^ I've already done this

And then going forward to all future sessions with new/different participants, they view the textblocks in the same order, and the assigned search letter mirrors that of the first session.

Does that make sense? Any help you can provide is greatly appreciated.

coolcam

Chris Crabbe

unread,
Mar 2, 2022, 1:49:05 PM3/2/22
to coolcam, oTree help & discussion
Hi Coolcam -

I think in this case probably it would just make sense to generate your block of search letters externally, and store it as a constant.  That way it would be constant across all sessions.

Thanks,
--Chris

Chris @ oTree

unread,
Mar 2, 2022, 1:51:24 PM3/2/22
to oTree help & discussion
Yes agreed.

coolcam

unread,
Mar 2, 2022, 5:56:40 PM3/2/22
to oTree help & discussion
That's what I was thinking too I just wanted to confirm no other way. So for example please see the screenshot below of a models.py page for a example of the situation described above.

Here I am defining the dictionary, letters_to_search, it's pulling as many 'ascii_lowercase' choices as the 'const.num_tasks'.

Then I create the variable search_letters, where the random encoding/assignment of letters_to_search for each passage starts to take shape. 

So, when you say randomly determine the search letter externally like in Excel, how would I then "hard code" that into my oTree app exactly? Is it something as simple as setting the search letter variable like search_letter_passage_1 = e, search_letter_passage_2 = b, etc. at the session level? And then pulling that session level variable forward? Sorry for all the follow-up questions, I really appreciate everything you do.

Screen Shot 2022-03-02 at 5.46.00 PM.png

Chris @ oTree

unread,
Mar 2, 2022, 6:03:35 PM3/2/22
to oTree help & discussion
Put the code to generate search_letters in a function, then in your constants class do e.g. SEARCH_LETTERS = make_search_letters()

coolcam

unread,
Mar 2, 2022, 6:07:50 PM3/2/22
to oTree help & discussion
Makes sense. Thank you!
Reply all
Reply to author
Forward
Message has been deleted
0 new messages