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
  • Jmantysalo's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
6 months 2 days ago #251500 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
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 months 2 days ago #251502 by tpartner
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
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 months 2 days ago - 6 months 2 days ago #251503 by Joffm
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.
 

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.

Lime-years ahead

Online-surveys for every purse and purpose