- Posts: 348
- Thank you received: 41
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Random value re-computed? Ramdomization over groups.
- Jmantysalo
- Topic Author
- Offline
- Platinum Member
Less
More
6 months 2 days ago #251500
by Jmantysalo
Random value re-computed? Ramdomization over groups. was created by Jmantysalo
I want to make a survey where by random either question A in group X or question B in group Y is shown. I think I could just use a hidden question of type equation "rand(1,2)" and show a question A if it was 1, question B if it was 2. But it does not work, it seems that the random number will be re-computed every time a new group is loaded. A bug or feature? If the latter, can I make something else, like taking last digit of seconds when the survey started?
Attachments:
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
6 months 2 days ago #251502
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Random value re-computed? Ramdomization over groups.
You need to test for an existing value. If, for example, you have question code "random1", the equation would be:
Code:
if(is_empty(random1), rand(1,2), random1)
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Jmantysalo
Please Log in to join the conversation.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12943
- Thank you received: 3979
6 months 2 days ago - 6 months 2 days ago #251503
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Random value re-computed? Ramdomization over groups.
Hi,
exactly. Each click changes the random number.
IF you create it as you did. Only {rand(1,2)}
To avoid this, use the construct that is shown here "more than 1000 times"
{if(is_empty(random),rand(1,2),random)}
Only as long as the random number is empty, it will be calculated. If not, it keeps its value.
Joffm
@tpartner beat me by two minutes.
exactly. Each click changes the random number.
IF you create it as you did. Only {rand(1,2)}
To avoid this, use the construct that is shown here "more than 1000 times"
{if(is_empty(random),rand(1,2),random)}
Only as long as the random number is empty, it will be calculated. If not, it keeps its value.
Joffm
@tpartner beat me by two minutes.
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 6 months 2 days ago by Joffm.
The following user(s) said Thank You: Jmantysalo
Please Log in to join the conversation.