Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

perform rand function only once per survey

  • Mndoughan
  • Mndoughan's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 2 months ago #192705 by Mndoughan
in a text display type question i have inserted this code:

please ask {if (rand(1,q1.value)==1, q2_A1_1.value, if (rand(1,q1.value)==2, q2_A2_1.value,if (rand(1,q1.value)==3, q2_A3_1.value, if (rand(1,q1.value)==4, q2_A4_1.value, if (rand(1,q1.value)==5, q2_A5_1.value,if (rand(1,q1.value)==6, q2_A6_1.value, if (rand(1,q1.value)==7, q2_A7_1.value, if (rand(1,q1.value)==8, q2_A8_1.value,if (rand(1,q1.value)==9, q2_A9_1.value, if (rand(1,q1.value)==10, q2_A10_1.value))))))))))} the following questions

it is randomly selecting a value you from a previous array but the issue is that i wanted it to perform it only once since if i pause the survey and i want to resume it late it will repeat the code and display a new value


how can i run this code only once per survey
thank in advance
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 2 months ago #192710 by tpartner
Replied by tpartner on topic perform rand function only once per survey
Place your random number in an equation type question and only fire the rand() function if it is empty.

For example, in an equation question with code "equation1":

Code:
{if(is_empty(equation1), rand(1, q1.value), equation1)}

Then, your piped text is:

Code:
{if equation1 == 1, q2_A1_1.value, 
  if equation1 == 2, q2_A2_1.value, 
    if equation1 == 3, q2_A3_1.value, 
        if equation1 == 4, q2_A4_1.value, 
          if equation1 == 5, q2_A5_1.value, 
            if equation1 == 6, q2_A6_1.value, 
              if equation1 == 7, q2_A7_1.value, 
                if equation1 == 8, q2_A8_1.value, 
                  if equation1 == 9, q2_A9_1.value, 
                    if equation1 == 10, q2_A10_1.value))))))))))}

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: gabrieljenik, Mndoughan
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose