Print random number on the screen

I want to print a random number (preferably alphanumeric, but any 6-digits numbers would do) at the end of my online experiment so that participants can contact me afterwards for payment or credit.

I would like each participant to have a different number rather than me creating a text component with the same number. Also, I want to be able to confirm this number in the participant file.

I imagine there is a formula that can be inserted into a text component and works on JS? I tried creating the numbers myself on an excel file, but then I wouldn’t know how to have only one selected rather than displaying every single code I created after participants presses enter to end experiment. Any help would be appreciated.

If you look at my crib sheet for how to define randint and thisExp you could just have:

codeNum = randint(100000,999999) in a code component along with

thisExp.addData(‘code’,codeNum)

and then just add str(codeNum) into your thank you message

If you want unique numbers you could append a participant number from my web app
https://moryscarter.com/vespr/pavlovia.php

1 Like

It worked perfectly, thanks so much!
I just had a bit of a hard time with the str in the text component when running it online, but then I added $String() and it worked. Thanks again!