There may be times when you want to create a random number, a value that uniquely identifies the participant, or a very unique random string.
If you need to create a random number and display it to a participant (while also recording the value as a response to a question), you need to create a question of Type = Equation.
Below we show two methods -- one where the number is stored as the response to a hidden question, and the other as just a random number displayed to the participant without it being stored anywhere.
1. To store the random number as the response to a question, create a Question type of Equation.
2. Assign your question code, and then in the Question text box, cut and paste the following:
{if(!is_empty(Q1),Q1,1*rand(157382, 908173))}
Note that this generates a random number: it does not guarantee a unique number across all responses, since it isn't validated against any pre-existing assigned values. If you choose a large range (ie rand(00000000,999999999) you increase the linkihood of a random value across all your survey responses.
Replace both instances of Q1 with your own question code.
Here's an example:
If you just want to display the random number to the participant and do not want the value to be stored against the participant's response, you can place this in any editor window (like question test or end message):
{rand(157382, 908173)}
You can generate a unique number by using a combination of the surveyID and the participant's response ID.
The number can only be displayed on the survey End Message (found under,Survey Properties->General Settings) and only works when your survey has been Activated.
Use the placeholders {SID} and {SAVEDID} to create a unique number:
{SID} = the survey ID
{SAVEDID} = the response number
You can use this in formats like:
{SID}{SAVEDID}
or
{SID}any characters{SAVEDID}
Note: With this approach, since you will have the survey response ID of the participant, if a participant provides you with their unique number, you will be able to identify their individual response. This would be a problem if you were running an anonymous survey.
<p id="uuid_p">UUID</p>
<script> function guid() { function s4() { return Math.floor((1 + Math.random()) * 0x10000) .toString(16) .substring(1); } return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); } $(document).ready(function() { $('#uuid_p').text(guid()); }) </script>