Welcome to the LimeSurvey Community Forum

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

Why does rand(1,3) return decimal numbers?

  • L_aura
  • L_aura's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 11 months ago - 8 years 11 months ago #119700 by L_aura
Hey everybody,

I hope this isn't a double post but I have been reading a lot of threads here during the last hours and couldn't seem to find a solution to my problem. So I really hope that you can help me.

Basically, I just want to include three different treatments in my survey and randomly select each participant into one of the treatments (of which each contains different questions).

I wanted to do so using a question group of the "equation type" called randnumber that includes

{if(randnumber>=1, randnumber, rand(1,3))}.

However, for some reason this doesn't seem to work for me. The question always returns a decimal number between 0 and 1 rather than an integer between 1 and 3.

In addition, even if I use ceil(rand(1,3)) instead of rand(1,3) and thus indeed do get "1" as a result, those questions for which I set the logic to ((randnumber=="1")) do not show up when going through the survey.

I guess those are, in fact, to distinct problems. But I really hope you can help me with that!

Thanks a lot in advance!

Laura

PS: I am using Version 1.92+ and have also tried the {if(is_empty(randnumber),rand(1,3),randnumber)} approach already.. without any changes
Last edit: 8 years 11 months ago by L_aura.
The topic has been locked.
More
8 years 11 months ago #119731 by jelo
Two remarks:

1.) Limesurvey is still on an old version. What is the buildnumber behind 1.92+?

2.) Why are you using the equation name inside the equation?
{if(randnumber>=1, randnumber, rand(1,3))}

How you assign the value to randnumber before reaching the equation with the same name?
I would use some additional variables names to prevent unwanted effects.

assign randnumberA

randnumber equation
{if(randnumberA>=1, randnumberA, rand(1,3))}

use randnumber

Try to define the randomnumber as early as possible in the survey. Think about effects when respondents can skip back and fourth in the survey. That triggers equations again.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 11 months ago #119768 by tpartner
Replied by tpartner on topic Why does rand(1,3) return decimal numbers?
@L_aura, I see nothing wrong with your equation and have tested it successfully in 1.92, build 120919. Please update to the latest stable version of 1.92 and retest. Or, ideally, update to 2.05.

@jelo, the IF statement in the equation prevents it from being re-fired when the page is revisited.


.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
8 years 11 months ago #119772 by jelo

tpartner wrote: @jelo, the IF statement in the equation prevents it from being re-fired when the page is revisited.

Had too many strange effects in the past. I don't rely on that. To often there is a regression with an update of Limesurvey.

What is the value of randnumber, the first time the equation is run? 0 or NULL?

I think I got the question wrong. The wording "question group of the "equation type" is a bit confusing.
Is the EQ Code in the Grouppart or is a dedicated equation question type used?

Let's see what feedback we get.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose