- Posts: 14
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
rand() seems to behave odd
- rakittam
- Topic Author
- Offline
- New Member
Less
More
2 years 9 months ago #217970
by rakittam
rand() seems to behave odd was created by rakittam
Limesurvey Version: Web application, version 3.27.4
Dear Community,
I am struggling with php's random number generator, rand(). It doesn't seem to be behaving as it should.
What I am doing is, creating three allocation variables, each randomly storing either a zero or a one, based on which participants are independently assigned to a control and a treatment groups for three different question tasks. The three allocation variables are each hidden equations in the same question group, coded groupIDsocial1, groupIDsocial2 and groupIDframing, and each with the question text {rand(1,2) - 1}.
These are later used to assign participants to control and treatment groups, e.g. using "Relevance equations" ((!is_empty(groupIDsocial1.NAOK) && (groupIDsocial1.NAOK == 1)))) for treatment (or == 0 for control)). While the assignment by the relevance equations works fine, the pattern of the three random number generators is strange to me.
I activated the survey and tested the whole procedure twice and everything worked for me. My three assignment variables in the two trials were:
My next approach would be to use rand(1,2), rand(3,4) and rand(5,6) for the three hidden equations. But unfortunately, I'm running out of money and don't have many experiments left..
Let me know if I should explain more. Thank you very much for your time!
Dear Community,
I am struggling with php's random number generator, rand(). It doesn't seem to be behaving as it should.
What I am doing is, creating three allocation variables, each randomly storing either a zero or a one, based on which participants are independently assigned to a control and a treatment groups for three different question tasks. The three allocation variables are each hidden equations in the same question group, coded groupIDsocial1, groupIDsocial2 and groupIDframing, and each with the question text {rand(1,2) - 1}.
These are later used to assign participants to control and treatment groups, e.g. using "Relevance equations" ((!is_empty(groupIDsocial1.NAOK) && (groupIDsocial1.NAOK == 1)))) for treatment (or == 0 for control)). While the assignment by the relevance equations works fine, the pattern of the three random number generators is strange to me.
I activated the survey and tested the whole procedure twice and everything worked for me. My three assignment variables in the two trials were:
- Run: groupIDsocial1 = 0, groupIDsocial2 = 0 and groupIDframing = 1
- Run: groupIDsocial1 = 0, groupIDsocial2 = 1 and groupIDframing = 1
- Participant: groupIDsocial1 = 0, groupIDsocial2 = 0 and groupIDframing = 0
- Participant: groupIDsocial1 = 0, groupIDsocial2 = 0 and groupIDframing = 0
- Participant: groupIDsocial1 = 0, groupIDsocial2 = 0 and groupIDframing = 0
- Participant: groupIDsocial1 = 1, groupIDsocial2 = 1 and groupIDframing = 1
- Participant: groupIDsocial1 = 1, groupIDsocial2 = 1 and groupIDframing = 1
- Participant: groupIDsocial1 = 0, groupIDsocial2 = 0 and groupIDframing = 0
- Participant: groupIDsocial1 = 1, groupIDsocial2 = 1 and groupIDframing = 1
- Run: groupIDsocial1 = 0, groupIDsocial2 = 0 and groupIDframing = 1
- Run: groupIDsocial1 = 0, groupIDsocial2 = 1 and groupIDframing = 0
- Participant: groupIDsocial1 = 1, groupIDsocial2 = 1 and groupIDframing = 1
- Participant: groupIDsocial1 = 1, groupIDsocial2 = 1 and groupIDframing = 0
- Participant: groupIDsocial1 = 1, groupIDsocial2 = 1 and groupIDframing = 0
- Participant: groupIDsocial1 = 1, groupIDsocial2 = 1 and groupIDframing = 1
- Participant: groupIDsocial1 = 1, groupIDsocial2 = 1 and groupIDframing = 0
My next approach would be to use rand(1,2), rand(3,4) and rand(5,6) for the three hidden equations. But unfortunately, I'm running out of money and don't have many experiments left..
Let me know if I should explain more. Thank you very much for your time!
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13597
- Thank you received: 2487
2 years 9 months ago - 2 years 9 months ago #217975
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic rand() seems to behave odd
Function from PHP
github.com/LimeSurvey/LimeSurvey/blob/43...core_helper.php#L220
php.net/rand
github.com/LimeSurvey/LimeSurvey/blob/43...core_helper.php#L220
php.net/rand
Ask to the support for a specific survey maybe ? www.limesurvey.org/support/contactMy next approach would be to use rand(1,2), rand(3,4) and rand(5,6) for the three hidden equations. But unfortunately, I'm running out of money and don't have many experiments left..
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 2 years 9 months ago by DenisChenu. Reason: https://www.limesurvey.org/support/contact
The topic has been locked.
- rakittam
- Topic Author
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 0
2 years 9 months ago - 2 years 9 months ago #217976
by rakittam
Replied by rakittam on topic rand() seems to behave odd
Sorry would do you mean with for a specific survey?
Last edit: 2 years 9 months ago by rakittam.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13597
- Thank you received: 2487
2 years 9 months ago #217977
by DenisChenu
BUT :
use {if(is_empty(self),rand(1,2) - 1,self.NAOK)}
Else : the number is updated each time an action is done, for example when move next …
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic rand() seems to behave odd
I mean : a lot of devlopper for PHP , not really a LimeSurey issue??
BUT :
use {if(is_empty(self),rand(1,2) - 1,self.NAOK)}
Else : the number is updated each time an action is done, for example when move next …
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
- rakittam
- Topic Author
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 0
2 years 9 months ago #217978
by rakittam
Replied by rakittam on topic rand() seems to behave odd
Oh, that sounds perfect, but I am not sure if I understand it right already. What is the "self" variable exactly? Do I define it or is this given by php or by limesurvey?
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13597
- Thank you received: 2487
2 years 9 months ago #217979
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic rand() seems to behave odd
self :
manual.limesurvey.org/Expression_Manager....27that.27_variables
Else :
manual.limesurvey.org/Expression_Manager...e_Question_Per_Group
> Note that the "if()" function first checks whether ask1 has already been set, and if so, uses that value. If the value hasn't been set, then it uses a random value to set the value of ask1.
Else :
manual.limesurvey.org/Expression_Manager...e_Question_Per_Group
> Note that the "if()" function first checks whether ask1 has already been set, and if so, uses that value. If the value hasn't been set, then it uses a random value to set the value of ask1.
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
- rakittam
- Topic Author
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 0
2 years 9 months ago #217999
by rakittam
Replied by rakittam on topic rand() seems to behave odd
Thank you again for your time!
So self is a reserved variable of Limesurvey. But the description in the manual is very sparse, or I don't quite understand it. How does this variable work? In my understanding self refers to the question itself which it is written in to. But what does it measure?
Trying around with the variable doesn't help. Writing self in a equation is always empty. However, writing is_empty(self) is empty too, and not 1 as I would have expected... But using a equation question with {if(is_empty(self),rand(1,2) - 1,self.NAOK)}, seems to correctly use the first if condition rand(1,2)... What is going on here?
In general, why the diversions and not just use rand(1,2) directly? What is the benefit and functioning in the diversions over the if?
Can you maybe describe specifically what happens to the self variable in an example?
Regarding manual.limesurvey.org/Expression_Manager...e_Question_Per_Group , thank you very much, is seems to work as desired! Unfortunately, I cannot understand why this strange construction works and mine won't... It seems also to use the diversions like you explained in your if-self example, maybe to somehow enforces the survey to really generate each time new random numbers with rand each time it checks the if and not sometimes reuse the rand(1,2) from a previous participant like in my example? But why would the code recompute this way and why wouldn't it when you just write three times just rand(1,2)? This seems so odd...
So self is a reserved variable of Limesurvey. But the description in the manual is very sparse, or I don't quite understand it. How does this variable work? In my understanding self refers to the question itself which it is written in to. But what does it measure?
Trying around with the variable doesn't help. Writing self in a equation is always empty. However, writing is_empty(self) is empty too, and not 1 as I would have expected... But using a equation question with {if(is_empty(self),rand(1,2) - 1,self.NAOK)}, seems to correctly use the first if condition rand(1,2)... What is going on here?
In general, why the diversions and not just use rand(1,2) directly? What is the benefit and functioning in the diversions over the if?
Can you maybe describe specifically what happens to the self variable in an example?
Regarding manual.limesurvey.org/Expression_Manager...e_Question_Per_Group , thank you very much, is seems to work as desired! Unfortunately, I cannot understand why this strange construction works and mine won't... It seems also to use the diversions like you explained in your if-self example, maybe to somehow enforces the survey to really generate each time new random numbers with rand each time it checks the if and not sometimes reuse the rand(1,2) from a previous participant like in my example? But why would the code recompute this way and why wouldn't it when you just write three times just rand(1,2)? This seems so odd...
Attachments:
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13597
- Thank you received: 2487
2 years 9 months ago #218021
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic rand() seems to behave odd
self is just a shortcut for the current question code …
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.