perform rand function only once per survey

1 year 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.
LimeSurvey Partners
1 year 2 months ago #192710 by tpartner
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":

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

Then, your piped text is:

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

Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner -
The following user(s) said Thank You: gabrieljenik, Mndoughan
The topic has been locked.

Start now!

Just create your account and start using Limesurvey today.

Register now