# Can I connect two random numbers

4 years 4 days ago - 4 years 4 days ago #119411 by ahaba
Hi,

at the moment, I´m creating a survey with version 2.05+ build 150413. Unfortunately, I do have problems with connecting randomly created numbers.

In part 1, I created a random number (rand1) between 1 and 8 with {rand(1, 8)}. Within the same question group I have 8 different pictures, whereas one of them opens depending of this number. This part of the survey is working so far.

After this part, there are following some question groups.

In part 2, I would like to fall back on the number which has been created in part 1 following this logic:

1) only if rand1 = 1: a new random number (rand2) between 2 and 8 should be created with the equation {rand(2, 8)}, which is connected to pictures B/C/D/E/F/G or H which are different to the ones shown in part 1

2) if rand1= 2, 3, 4, 5, 6, 7, 8: directly (without random number) a connection to picture B/C/D/E/F/G or H should be executed.

I tried to scratch the logic for better understanding...

#### File Attachment:

File Name: logic.pdf
File Size:252 KB

The problem I have, is that the second random number is working every time, detached from what the result of the first random number is. Probably the rand1 number is not saved (?) and therefore rand2 causes a new rand1 number, which might by luck be right, but most of the time not?!

I hope some of you can help me

Thanks so far,
Andi
##### Attachments:
Last edit: 4 years 4 days ago by ahaba.

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

LimeSurvey Partners
4 years 4 days ago #119414 by tpartner
It seems to me that the equation for rand2 should be as follows. This should load the following for rand2:
- If rand1 equals 1: a random number between 2 and 8
- Otherwise: 1
`{if(rand1 == '1', rand(2, 8), 1)}`

So, then the relevance for picture "B" in part 2 would be:
`{rand1 == '2' OR rand2 == '2'}`

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

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

4 years 4 days ago #119422 by ahaba
Thanks für your help tpartner,

unfortunately the solution you sent me does not work.

I deleted now rand2 completely from the survey. however that didn't change the outcome and the two parts where not connected correct?!

might it be, that random numbers are created new, if a following condition is set and therefore asks for a new random number?

Thanks so far,
Andi

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

4 years 3 days ago #119454 by tpartner
Can you attach a small sample survey?

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

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

4 years 3 days ago - 4 years 3 days ago #119457 by ahaba
i just did this, with less versions to make it less complex, but the logic should be the same...

thanks for your help!
Last edit: 4 years 3 days ago by ahaba.

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

4 years 3 days ago #119459 by tpartner
No attachment.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

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

4 years 3 days ago - 4 years 3 days ago #119461 by ahaba
I tried to attach something, but that does not work
##### Attachments:
Last edit: 4 years 3 days ago by ahaba. Reason: no it worked ;-)

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

4 years 3 days ago - 4 years 3 days ago #119463 by tpartner
Okay, try this.

I have:
• Removed a bunch of unnecessary HTML from the equation questions (maybe you pasted direct from a web page?).
• Removed the condition on rand2.
• Added a check for the equation questions so they only get populated once. The equations for this simplified version are now:
`{if(rand1 == '', rand(1,4), rand1)}`
`{if(rand2 == '', if(rand1 == '1', rand(2, 4), 1), rand2)}`

Modified survey attached:

#### File Attachment:

File Name: limesurvey...6628.lss
File Size:17 KB

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
##### Attachments:
Last edit: 4 years 3 days ago by tpartner.
The following user(s) said Thank You: ahaba

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

4 years 3 days ago #119465 by ahaba
Great, thank you, that´s the solution!!

You saved my master thesis

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

4 years 3 days ago #119467 by tpartner
Add me to the credits

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

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

4 years 3 days ago #119468 by ahaba

so far I added you or rather lime survey to my credit card... hope thats good as well

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

4 years 3 days ago #119469 by tpartner
Even better!

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

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

## Start now!

#### Just create your account and start using Limesurvey today.

Join our Newsletter!