problems randomising survey using rand().

More
6 years 11 months ago - 6 years 11 months ago #82187 by zz07
Hi,

I have a survey (build Version 1.92+ Build 120608) with two sets of question groups. Each set contains 5 question groups. I want to randomise whether a participant is shown set 1 or set 2, but they are never shown both.

I have done this by creating both sets of question groups, and including an introduction group for the survey that is shown to everyone. In this introduction I have a question (equation type) which states rand(1,2), which I called 'random'.

For each question group in set 1 I have put (random==1) for relevance, and (random==2) for set 2.

This is the problem - the survey often displays the wrong set of questions. If 'random' is 2, it will display set 1. If 'random' is 1, it will also display set 1.

But if I change random to rand(2,2), it always (correctly) displays set 2 only. And if it is rand(1,1) it will always (also correctly) display set 1 only. So it seems that the relevance sections on the sets are not the problem.

I tried changing the relevance expression for set 1 to '(random == 1) and (random != 2)' or '(random != 2)', which should produce the same behaviour. But in fact it means that whenever random is 1, it displays set 2, and when random is 2, it still displays set 2.

I make sure to delete the cookies from my browser, just in case that is causing the problem - but it appears to have no effect.

I created a second survey as a test. I created 5 question groups, and gave each a different relevance equation - so question group 1 was (random==1) and question group 5 was (random==5). I created the same introduction question group and a 'rand(1,5)' equation question. Essentially the question group shown did not match the 'random' number generated. While only 1 group was ever shown, it was always a different group to the 'random' variable created.

Does anyone know why this is happening and of a solution to randomly showing 1 of 2 sets of questions?

I am currently using XAMPP while I design the survey.

Thank you very much for your help and feedback. I can upload the lss file if helpful.
Last edit: 6 years 11 months ago by zz07.

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

LimeSurvey Partners
More
6 years 11 months ago #82233 by TMSWhite
The most likely reason is that the rand() function is called each time the page is visited AND each time it is validated. Did you follow the recommendations of this example , which shows how to ensure that rand() is only called once during the survey?

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

More
6 years 11 months ago #82234 by Mazi
Your approach matches the suggested solution at this blog post at www.limesurvey-consulting.com : How to randomly show 1 of X questions at a Limesurvey survey

Only difference I can see is that the quotes are missing: ((randnumber=="1"))
...but this should make no difference.

You can test if this is fixed at the latest version by testing our online Demo which always runs the latest Limesurvey version.
Username: admin
Password: test
If you can reproduce the problem there please report back and attach your survey for testing.

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com
Want to use your survey offline -> www.offlinesurveys.com

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

More
6 years 11 months ago #82235 by TMSWhite
Mazi-

The blog post isn't quite accurate. The equation for "randnumber" should be:
{if(randnumber>0,randnumber,rand(1,2))}

Otherwise, the random value will change with each page, and even each time you try to validate the entered data.
The following user(s) said Thank You: kaled_fr

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

More
6 years 11 months ago #82249 by zz07
Hi,

Thank you both for the replies.

I looked at the example you (TMSWhite) suggested - I missed that one before.

I changed the equation expression to {if(random>=1, random, (rand(1,2)))} and now everything works fine. So you were right about it running the rand() multiple times.

Thanks very much. Very helpful.

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

More
6 years 11 months ago #82252 by Mazi
Thanks for the hint, Tom.

I think I had set it up the way explained at the blog and it worked fine. Is that related to the survey mode?
Because I think since the question is only called once (if you disable the back button) and thus the created random number is fixed?

How can the value change if I just use an ((randnumber=="2")) relevance at several questions?

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com
Want to use your survey offline -> www.offlinesurveys.com

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

More
1 year 4 months ago - 1 year 4 months ago #162307 by jkautto
Apparently this is still an issue with limesurvey 2.73, after 5 years or so? To pick a random question one MUST use the trick

{if (num>=1,num,rand(1,N))}

in order to make sure there is ONLY ONE random number generated per page.

I find that when using simple "{rand(1,N)}" the numbers in the response table are INCORRECT and there is no way to actually know which questions were shown to a participant (i.e., data is useless).

Can someone please verify that this trick is still the best way to go with 2.73?


ADDITION: My random questions have type "Text display", so no responses are stored in the result table. However, generated random numbers are stored and they are needed to find out visible texts.
Last edit: 1 year 4 months ago by jkautto.

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

More
1 year 4 months ago #162319 by tpartner
Yes, this is the correct way to load a random number.

Sorry, I have no clue what you are asking in the "Addition".

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
The following user(s) said Thank You: jkautto

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

More
1 year 4 months ago - 1 year 4 months ago #162323 by jkautto
Thanks! That's really all I needed. I didn't have any other questions.

In my addition I just wanted to point out that "text display" is special as it does not store any data into response table. You REALLY need to store correct random values. With other question types even the simple {rand(1,N)} might suffice.
Last edit: 1 year 4 months ago by jkautto.

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

More
1 year 4 months ago #162329 by tpartner
Yeah, this may be a good opportunity to use the custom question templates available in 3.x - based on a numeric-input. I'll play with that and report back.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com

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

More
4 months 4 days ago #179364 by FeCanever
I have 8 study conditions, and have created 8 questions groups with a couple of questions each. I've been able to set up the question randomization inside each group (I need that) , but still haven't been able to set up the condition assignment so that each participant gets assigned a condition and is presented with one group of questions.
I have created an initial equation question and have inserted in the question field: if(random >= 1, random, (rand(1, 2)))

I then added ((random == 1)) and ((random == 2)) to the relevance field in each of the group settings. None of the group questions appears when I click to preview survey.

Should I add ((random == 1)) to each of the questions relevance box? Or is there a way of linking the assigned condition directly to the question group?

I'd really appreciate if anyone could help me out with that.

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

More
4 months 4 days ago #179377 by tpartner
It seems to me that the equation in question code "random" should be:

if(random >= 1, random, rand(1, 8))

Then in the relevance field for group-1:

random == 1

In the relevance field for group-2:

random == 2

And so on...

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com

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

More
4 months 4 days ago #179378 by FeCanever
Hi, Tony,

first of all thanks for the quick answer. In my survey there will be 8 conditions, but I forgot to say that for now I was testing with 2. Sorry about that.

So you're saying it is possible to add the assigned info (random == 1, random == 2, and so on) to the relevance field for group instead of doing that for each question inside the group.

I just did what you said for the 2 groups I'm testing with and no question groups are displayed when I preview the survey.

What do you think I'm doing wrong?

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

More
4 months 4 days ago #179380 by FeCanever
Hi again,

I tried ((random == "1")) instead of ((random == 1)) and now it works!

Thanks a lot!
The following user(s) said Thank You: DenisChenu

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

More
4 months 4 days ago #179383 by DenisChenu

FeCanever wrote: Hi again,

I tried ((random == "1")) instead of ((random == 1)) and now it works!

Thanks a lot!

It's an issue , because it work like you say in 2.6lts and 2.73.

I think you must report it.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand .
An error happen ? Before make a new topic : remind the Debug mode .

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

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!