Random Number Generator

PennController for IBEX Forums Support Random Number Generator

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #6007
    caljones
    Participant

    Hi Jeremy,

    Hope you are doing well. I am trying to insert a random number generator at the end of my experiment to be used as a Participant ID. Ideally, this number would be randomly generated and then presented to participants on a screen at the end of the trial, as well as recorded in the result file in each line of the experiment. However, I am unsure if I can retroactively add an ID line in each result file line, and I am also unsure how to embed a random number generator.

    Thanks,
    Callie

    #6014
    Jeremy
    Keymaster

    Hello Callie,

    Sorry for the late reply, I was away from the office last week. What you can do is generate the random number at the beginning of the experiment, but present it only at the end. Here’s a dummy experiment for illustration purposes:

    PennController.ResetPrefix(null) // Shorten command names (keep this line here)
    
    uniqueID = [1,2,3,4].map(v=>Math.floor((1+Math.random())*0x10000).toString(16).substring(1)).join('-');
    
    Header(
        // void
    )
    .log( "ID" , uniqueID )
    
    newTrial("intro", newButton("Hello").print().wait() )
    newTrial("experiment", newButton("World").print().wait() )
    SendResults()
    newTrial("end", newText("your id: "+uniqueID).print(),newButton().wait() )

    Let me know if you need assistance adapting this to your case

    Jeremy

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.