Generate code at the end of survey - for mTurk

More
3 years 6 months ago #128638 by EmE9
Hello,

I would like to use LimeSurvey on mTurk and I need a way to generate a unique code (randomly) in the end message, that would be saved in the survey results preferably. In order to get paid, participants can then type in the code in mTurk and I would know that they have actually finished the survey.

Any help would be appreciated as I have not found good info on this problem

Best,

Please Log in or Create an account to join the conversation.

LimeSurvey Partners
More
3 years 6 months ago #128639 by Ben_V
Hi ,
there are 2 old great posts about this topic (using differents ways)... here (using Expression Manager) and there (using chance.js)

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)

Please Log in or Create an account to join the conversation.

More
3 years 6 months ago #128644 by EmE9
Hi,

thanks a lot. If I could have just a bit of your time since I am a total beginner. I have seen this SAVEDID option but I am not sure to what it relates to. Is this an option that is choosable or is it something that I need to have coded for. Plus, how would this ID be shown to the participants at the end?

All the best,

Please Log in or Create an account to join the conversation.

More
3 years 6 months ago #128646 by Ben_V
"SAVEDID" is the respondant ID. It's a unique number (incremental, start is #1) for a survey but if you have several survey it's not so unique. You can print it at the end using the placeholder {SAVEDID}

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)

Please Log in or Create an account to join the conversation.

More
3 years 6 months ago - 3 years 6 months ago #128654 by tpartner

...but if you have several survey it's not so unique.

You can combine it with the survey ID.

{SID}{SAVEDID}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Last edit: 3 years 6 months ago by tpartner.

Please Log in or Create an account to join the conversation.

More
3 years 6 months ago #128658 by EmE9
Thanks to all.

If anybody else stumbles on this, I've managed to produce a random string of digits using the code already mentioned in one of the linked pages above.

{if(!is_empty(PIN),PIN,1*rand(357382, 908173))}

"PIN" is the name of your question group or just the questions (this can obviously be anything you want to name it). For me, as is per usual in mTurk, it was important to have a six digit number so I just basically said the rand() function to randomise between two six digit numbers (they can also be anything really). Not the most elegant solution but it works.

Hope it helps.

Please Log in or Create an account to join the conversation.

More
3 years 6 months ago #128659 by holch
You are aware that the same code could appear more than once, right? Ok, the chance is low, but it is there...

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in or Create an account to join the conversation.

More
3 years 6 months ago #128663 by EmE9
Yes, absolutely, but I'm starting the study in one day, so I'm willing to accept the risk. Plus, the, admittedly low chance of reoccurrence is worth it as I plan on some 100 - 200 participants.

Do you have a way of ensuring that it never repeats?

Best,

Please Log in or Create an account to join the conversation.

More
3 years 6 months ago #128665 by tpartner

Do you have a way of ensuring that it never repeats?

Incorporate the SAVEDID as Ben suggests.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com

Please Log in or Create an account to join the conversation.

More
3 years 6 months ago #128666 by Ben_V
The problem with the SAVEDID is it can be 1, 2, 3 (even more) digits, so an advanced equation is required to match the required length...
Using time() & rand () with 6 digits, an option is:
{if(!is_empty(PIN),PIN,substr(time()*rand() , 3 ,6))}
(IMHO, with 200 participants, the probability of duplicate PIN outputs, may be the same than for of a sudden meteor shower on the server)

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)

Please Log in or Create an account to join the conversation.

More
3 years 6 months ago - 3 years 6 months ago #128667 by tpartner

The problem with the SAVEDID is it can be 1, 2, 3 (even more) digits

You can pad it with zeros depending on the length.

{if(strlen(SAVEDID) < 4, 0, '')}{if(strlen(SAVEDID) < 3, 0, '')}{if(strlen(SAVEDID) < 2, 0, '')}{SAVEDID}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Last edit: 3 years 6 months ago by tpartner.

Please Log in or Create an account to join the conversation.

More
3 years 6 months ago - 3 years 6 months ago #128669 by holch
But if you have a fixed length code randomly generated number and then join the saved id at the end it should be fine. At least if you don't care that the final code could be anything from 7 to 9 digits long. But you will know that everything after the sixth digit is the savedid.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds
Last edit: 3 years 6 months ago by holch.

Please Log in or Create an account to join the conversation.

More
3 years 6 months ago #128672 by EmE9
These are all excellent suggestions. I will try to tweek the code a bit, but I'm kinda hoping that the chances for a repeat are pretty low for the number of participants that I am looking for.

All the best,

Please Log in or Create an account to join the conversation.

More
3 years 6 months ago #128685 by Ben_V

tpartner wrote: You can pad it with zeros depending on the length.


Brillant!

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)

Please Log in or Create an account to join the conversation.

More
3 years 6 months ago #128703 by jelo

Ben_V wrote:

{if(!is_empty(PIN),PIN,substr(time()*rand() , 3 ,6))}
(IMHO, with 200 participants, the probability of duplicate PIN outputs, may be the same than for of a sudden meteor shower on the server)

Depends on the PHP rand implementation. Is rand() in EM the php rand() function.

Always interesting to look at the comments of these PHP functions.
php.net/manual/en/function.rand.php

Many are old and may no longer valid with current PHP versions but there is dependency to other code parts (like libc rand()) which can change from environment to environment.

The uniqid function shows some interesting comments too.
php.net/manual/en/function.uniqid.php

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The following user(s) said Thank You: Ben_V

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!