- Posts: 25
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Not-so-random assignment to conditions
- vadindot
- Topic Author
- Offline
- Junior Member
Less
More
6 years 2 months ago - 6 years 2 months ago #163251
by vadindot
Not-so-random assignment to conditions was created by vadindot
I have a really long survey that is actually broken into two halves. After the first few questions, I need to assign someone to the first half or second half.
Basically it will work like this:
if (st1=3 or st1=4 or st4_2 >= 1) then they are automatically assigned the first half, otherwise I need to have them randomly assigned into either
so I'm guessing that some sort of equation is in order, I think this will do it, but I can use some extra eyes:
{if((st1.NAOK=||st1.NAOK==4||st4_2.NAOK >= 1),1,floor(rand(1,2.999)))}
Does anyone see any flaws in my idea or in my equation?
Basically it will work like this:
if (st1=3 or st1=4 or st4_2 >= 1) then they are automatically assigned the first half, otherwise I need to have them randomly assigned into either
so I'm guessing that some sort of equation is in order, I think this will do it, but I can use some extra eyes:
{if((st1.NAOK=||st1.NAOK==4||st4_2.NAOK >= 1),1,floor(rand(1,2.999)))}
Does anyone see any flaws in my idea or in my equation?
Last edit: 6 years 2 months ago by vadindot.
The topic has been locked.
- vadindot
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 25
- Thank you received: 0
6 years 2 months ago #163255
by vadindot
Replied by vadindot on topic Not-so-random assignment to conditions
in testing so far, I am running into the following issue: the equation above sometimes spits out the number "3"
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10103
- Thank you received: 3593
6 years 2 months ago - 6 years 2 months ago #163260
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Not-so-random assignment to conditions
I don't understand the use of floor().
How about this:
That should return 1 if st1.NAOK= OR st1.NAOK==4 OR st4_2.NAOK >= 1. Otherwise it will return a random number 1 or 2.
How about this:
Code:
{if(st1.NAOK==3 || st1.NAOK==4 || st4_2.NAOK >= 1, 1, rand(1, 2))}
That should return 1 if st1.NAOK= OR st1.NAOK==4 OR st4_2.NAOK >= 1. Otherwise it will return a random number 1 or 2.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 years 2 months ago by tpartner.
The topic has been locked.
- jelo
- Offline
- Platinum Member
Less
More
- Posts: 5033
- Thank you received: 1257
6 years 2 months ago #163275
by jelo
Not the issue with php rand(), which is returning integer.
Other reason was the distribution of random number between two numbers.
The typical concept often used than was this:
In the old days the random routines where not that random.
PHP 7.X has changed the underlaying routine.
Compare notes in this bugticket:
bugs.limesurvey.org/view.php?id=12248
The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
Replied by jelo on topic Not-so-random assignment to conditions
Typical rand routines in many programming-languages are not returning whole numbers.tpartner wrote: I don't understand the use of floor()
Not the issue with php rand(), which is returning integer.
Other reason was the distribution of random number between two numbers.
The typical concept often used than was this:
In the old days the random routines where not that random.
PHP 7.X has changed the underlaying routine.
Compare notes in this bugticket:
bugs.limesurvey.org/view.php?id=12248
The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
- vadindot
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 25
- Thank you received: 0
6 years 2 months ago #163406
by vadindot
Replied by vadindot on topic Not-so-random assignment to conditions
after testing, it looks as though floor isn't needed, and rand does return an integer
Thanks!
Thanks!
The topic has been locked.