Welcome to the LimeSurvey Community Forum

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

Can I connect two random numbers

More
8 years 10 months ago - 8 years 10 months ago #119411 by ahaba
Can I connect two random numbers was created 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: 8 years 10 months ago by ahaba.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 10 months ago #119414 by tpartner
Replied by tpartner on topic Can I connect two random numbers
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
Code:
{if(rand1 == '1', rand(2, 8), 1)}

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

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
8 years 10 months ago #119422 by ahaba
Replied by ahaba on topic Can I connect two random numbers
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
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 10 months ago #119454 by tpartner
Replied by tpartner on topic Can I connect two random numbers
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.
The topic has been locked.
More
8 years 10 months ago - 8 years 10 months ago #119457 by ahaba
Replied by ahaba on topic Can I connect two random numbers
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: 8 years 10 months ago by ahaba.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 10 months ago #119459 by tpartner
Replied by tpartner on topic Can I connect two random numbers
No attachment.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
8 years 10 months ago - 8 years 10 months ago #119461 by ahaba
Replied by ahaba on topic Can I connect two random numbers
I tried to attach something, but that does not work
Attachments:
Last edit: 8 years 10 months ago by ahaba. Reason: no it worked ;-)
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 10 months ago - 8 years 10 months ago #119463 by tpartner
Replied by tpartner on topic Can I connect two random numbers
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:
    Code:
    {if(rand1 == '', rand(1,4), rand1)}
    Code:
    {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.
Last edit: 8 years 10 months ago by tpartner.
The following user(s) said Thank You: ahaba
The topic has been locked.
More
8 years 10 months ago #119465 by ahaba
Replied by ahaba on topic Can I connect two random numbers
Great, thank you, that´s the solution!!

You saved my master thesis :P
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 10 months ago #119467 by tpartner
Replied by tpartner on topic Can I connect two random numbers
Add me to the credits :)

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
8 years 10 months ago #119468 by ahaba
Replied by ahaba on topic Can I connect two random numbers
:D
so far I added you or rather lime survey to my credit card... hope thats good as well ;-)
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 10 months ago #119469 by tpartner
Replied by tpartner on topic Can I connect two random numbers
Even better!

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose