Welcome to the LimeSurvey Community Forum

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

Bias in rand function for random number generation ?

  • lea_crtl
  • lea_crtl's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 month 3 weeks ago #258061 by lea_crtl
Hi, yes I'm sorry this is not a minimal example at all, my survey is quite complicated. The names might not help either (many are identical), so I'm just going to give you the Group and Question orders. I hope this works.

Variables defined in questions 5/1 to 5/4 are other random variables that I use for tayloring (I'm making a reference to what Joffm explained) respectively in questions 7/0 & 8/0, 9/0 & 10/0, 11/0 & 12/0, 13/0 & 14/0. Again, contrarily to what Joffm said, I did not notice any switch in values when I call these variables in my image paths. Out of 63 responses, I conclude that it simply does not happen?

Variable defined in question 5/7 is the variable my original question was about. If it is equal to 1, groups 15 to 18, 24 to 33, and 46 to 55 will display. If it is 2, it will be groups 19 to 22, 34 to 43 and 56 to 65.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Online
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 3 weeks ago #258065 by Joffm
What I see, is that the random numbers are generated as
 
but in the dataset you see this
 

The click on "next" changes the random numbers.
So it is dangerous to use the plain "rand()" function.

If it is fine in your survey, the correct questions/groups are displayed as stored in the dataset, don't care.

And your question about the distribution is answered.

BTW: In version 6.x there is no class "hidden".
As Limesurvey now is based on bootstrap 5, this class is called "d-none"

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Online
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 3 weeks ago #258068 by Joffm
One last word.
Your advantage is that the generation of random numbers take place in a separate group.
So it doesn't matter that they change when you leave this group.
Would affect the survey if there were questions inside this group that depend on the random number.

And of course if participants go back to the demographics, pass the "random" group again, they will be surprised to see different questions this time.
But this is the only point that you can avoid by hiding the "back" button generally or by javascript in the first question after the "random" group.

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 3 weeks ago #258069 by holch
Joffm, I am not sure if I understand you correctly. But it seems that you are suggesting that if the random number generation is in a different question group it doesn't change when questions in later groups have conditions based on this random number.

But according to my small test, any condition calls the equation and this will have a new rolling of the dice as a result.

Not sure if I am wrong or if I am understanding you wrong.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Please Log in to join the conversation.

More
1 month 3 weeks ago #258072 by jelo

Again, contrarily to what Joffm said, I did not notice any switch in values when I call these variables in my image paths. Out of 63 responses, I conclude that it simply does not happen?
What do you mean by "not notice"? How do you check if the equation is executed again or not?
The golden standard is to fixate the random number via the "is_empty" function.

LimeSurvey is using PHP functions to create the random numbers. If there are issues it might be depending on your webstack and PHP version you use.
Seldom these days, but  I wouldn't rule that out.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The following user(s) said Thank You: lea_crtl

Please Log in to join the conversation.

  • lea_crtl
  • lea_crtl's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 month 3 weeks ago - 1 month 3 weeks ago #258078 by lea_crtl
As you may have understood, I define the random variable in the beginning, in a given question group. Later, 10 groups are displayed only if the condition rand == 1 is verified, then similarly 10 groups call the condition rand == 2, then 10 groups again call the condition rand == 1, and finally 10 groups call the condition rand == 2. So in my survey, there are 40 condition calls on the random variable! If, as it was assumed, the value of the random variable changes everytime a condition is called, I should have observed in the database (since my survey is already launched, I just looked at the response table) cases where for the same respondent, question groups for rand == 1 AND rand == 2 appear. However this never happened. This is still unclear why the small test that holch conducted led to different results though.
Last edit: 1 month 3 weeks ago by lea_crtl. Reason: English mistake

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 3 weeks ago #258086 by tpartner
As far as I know, the equations to generate the random numbers are only fired when their group is opened or submitted. The resulting random numbers should not be modified by accessing them later in the survey.

Having said that, yes, always good to use is_empty to lock them after the first assignment.

Cheers,
Tony Partner

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

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 3 weeks ago #258099 by holch

As far as I know, the equations to generate the random numbers are only fired when their group is opened or submitted. The resulting random numbers should not be modified by accessing them later in the survey.


Thanks for chiming in Tpartner. It is always good to have experienced LS users to contribute their knowledge.

However, my little test yesterday makes me believe otherwise. I will have to test this again. Maybe I made a mistake yesterday.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose