Welcome to the LimeSurvey Community Forum

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

random number from numerical input question

  • vzyldd
  • vzyldd's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
2 years 4 days ago #233553 by vzyldd
Please help us help you and fill where relevant:
Your LimeSurvey version: 3.22.19+200605
Own server or LimeSurvey hosting: Own
Survey theme/template: extends-fruity
==================
Greetings.

I need to display a random number between 1 and using a number input from a numerical question to determine the random range.
Q1 asks how many people in a household (e.g. 7)
Q2 needs to display a random number from 1 to 7 then (to randomly determine who to select for an interview)

I know how to generate a random number in a fixed range using {if(is_empty(randnumber),rand(1,75),randnumber.NAOK)} but have no idea how to use the numerical input in this equation - if at all possible.

Once again I call on the experience and knowledge of this forum to give me some guidance.
Many thanks
 

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 4 days ago #233562 by holch
Why do you not use q1 to pipe the answer from q1 into the equation of q2?

To use the response from q1 in the equation of q2 they need to be on different pages. Because the equation needs to be "triggered" somehow.

By the way, you should never include HTML code into equation questions, because then you can't use the result of the equation anymore for any calculations later on.

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.

  • vzyldd
  • vzyldd's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
2 years 4 days ago #233566 by vzyldd
Replied by vzyldd on topic random number from numerical input question
Holch, thank you for the quick reply.

Sadly, I have no idea how to pipe the answer in q1 into the equation.

My second issue (that you pointed out), is that the survey is displayed all-in-one (client instruction) as it is used in an interview-style survey.

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 4 days ago #233567 by holch
Just put "q1" where the maximum for the random number should go. Done (aka sustitute 75 with q1)

Attached a working example.

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.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 4 days ago #233568 by holch
And you really should update your installation. LS 3.22.19+200605 is from mid 2020, so 1,5 years without updates, bug and security fixes...

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.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 4 days ago #233569 by holch

My second issue (that you pointed out), is that the survey is displayed all-in-one (client instruction) as it is used in an interview-style survey.


Well, then I don't think it will work. The equation is fired when you load the page and if everything is on one page (which I never recommend) there is no way to "fire" the equation again.

If you can't change it to group by group you might have to find a Javascript solution, but I won't be of help there.

All in all, I never recommend a all in one survey. Not sure why a "interview style" survey would require all in one, but there might be a good reason that I just don't see.

But you hardly just "jump around" to random questions, which also wouldn't work in your case anyway, because you first NEED to ask for the number of people in the household and only then the person can be drawn at random.

An alternative that is often used in market research is to ask for the person that has birthday next (or had birthday last). This is random and you don't need to make this kind of calculation.

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.

  • vzyldd
  • vzyldd's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
2 years 4 days ago #233570 by vzyldd
Replied by vzyldd on topic random number from numerical input question
Big thank you, Holch. This is a big big help.

The reason for the all-in-one display has to do with our power network - or lack thereof. Here in South Africa, we have load-shedding (stages during the day when there is no power) and it also affects internet connections. We have to run the survey on an offline app during these stages and sync it when the networks are available again. The app works best with the all-in-one setting.

Appreciated your help.

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 4 days ago #233576 by holch
I almost thought this would be the reason. Yes, Offlinesurvey.com needs to run as all in one, which is of course not ideal. I don't think my solution will work in an all-in-one setting.

Here in South Africa, we have load-shedding (stages during the day when there is no power) and it also affects internet connections. We have to run the survey on an offline app during these stages and sync it when the networks are available again.


Luckily this becomes less and less relevant for us here in Brazil, at least in the more urban areas. Power outages can happen, but then it is usually due to a storm or very specific occurrences and then usually research needs to stop anyway.

Now in more rural areas this is still relevant and then offline apps are needed.

A couple of years ago I ran a webserver on my smartphone for test purposes and it actually worked quite well. Of course, nothing near as comfortable than an app, but as it was a full PHP/MYSQL stack it could run Limesurvey just like a normal web application. Of course, the effort to install and maintain LS as a separate installation on each device is less than ideal.

Maybe check with the developers of Offlinesurveys.com (there is a specific subforum for that here) if they have a solution for what you are trying to do. But I think in your case, there are workarounds that have worked over centuries when questionnaires where still paper and pencil and I think for your specific case, the "birthday" solution is not worse than the the random number and is a proven method.

Of course, this might not be what the client has asked for, but it works. ;-)

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.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose