Generate a Random Number, Unique Response Identifier, or Pseudo-Unique UUID

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. 

Option A. Generate and Record a Random Number

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)}

Option B. Creating a Unique PIN Number

If you want to create a number to link a participant back to a survey and their specific response ID, you can use the surveyID and responseID to create a unique PIN number.

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.

Option C. Creating a Very Unique Value (UUID)

The following will mimic the creation of a universally unique identifier -- it is still random string generation, but due to its length and possibilities, the odds of the same value being created twice are very small. A UUID will look like:

67a247ed-9db1-6490-026f-c57676d760a9
 
1. In the location you want to display the UUID, paste the following (be sure to click the Editor's source view to enter the following):
<p id="uuid_p">UUID</p> 
2. While in source view, also paste the following:
<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>
23 of 58 people found this helpful.   




Powered by LiveZilla Live Chat