Welcome to the LimeSurvey Community Forum

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

Not-so-random assignment to conditions

  • vadindot
  • vadindot's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
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==3||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
  • vadindot's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
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
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 2 months ago - 6 years 2 months ago #163260 by tpartner
Replied by tpartner on topic Not-so-random assignment to conditions
I don't understand the use of floor().

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==3 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.
More
6 years 2 months ago #163275 by jelo
Replied by jelo on topic Not-so-random assignment to conditions

tpartner wrote: I don't understand the use of floor()

Typical rand routines in many programming-languages are not returning whole numbers.
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:
Code:
FLOOR((RAND() * (max-min+1))+min)

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
  • vadindot's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
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!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose