Welcome to the LimeSurvey Community Forum

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

Random Question

  • Thathekes_53133
  • Thathekes_53133's Avatar Topic Author
  • Offline
  • Banned
  • Banned
More
8 years 10 months ago #129298 by Thathekes_53133
Random Question was created by Thathekes_53133
Hi,

I should create a questionnaire in which 1 out of 15 possible vignettes should appear randomly. Then a few question will be asked about the shown vignette. To do this, First of all I create a Equation type question with code (q1) and question text of {q1=rand(1,15)}.
Then I create 15 question of type Text Display with codes s1-s15 each of which contain a vignette. In the Relevance equation of s{i} 1<i<15 I put (255193X3X28.NAOK==i) meaning that I want to show the i-th question if the random generated number is i.

The problem is that the shown vignette is not the same as the generated number.
To find the problem I mark the q1 question to be shown so I would know what random number is generated.
Also in the question text of each s1-s15 I put {255193X3X28.NAOK} to know if currently used number is the same as the generated one.

And surprise! They are not the same. I'm not sure what the problem is and I'm really confused.
I appreciate any help.

ps:By the way 255193X3X28 is the id for q1.
The topic has been locked.
  • holch
  • holch's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 10 months ago #129301 by holch
Replied by holch on topic Random Question
Why mixing SGQA codes with question codes?

In the relevance equation you put simply this:

For question s1 it would look like this:
Code:
q1==1
For question s2:
Code:
q1==2

And so on.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The following user(s) said Thank You: Thathekes_53133
The topic has been locked.
  • holch
  • holch's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 10 months ago - 8 years 10 months ago #129302 by holch
Replied by holch on topic Random Question
By the way, in my opinion the right code for q1 should be something like:
Code:
{rand(1,15)}.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Last edit: 8 years 10 months ago by holch.
The following user(s) said Thank You: Thathekes_53133
The topic has been locked.
  • Thathekes_53133
  • Thathekes_53133's Avatar Topic Author
  • Offline
  • Banned
  • Banned
More
8 years 10 months ago #129305 by Thathekes_53133
Replied by Thathekes_53133 on topic Random Question
It is not about using SGQA or question code. I think they are pretty much the same. (at least in this case). Anyways I changed it to what you said and no success!
Changing the equation for q1 to {rand(1,15)} didn't help neither.
The topic has been locked.
  • holch
  • holch's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 10 months ago #129306 by holch
Replied by holch on topic Random Question
Are your questions q1 and s1 to s15 on the same page?

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • holch
  • holch's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 10 months ago - 8 years 10 months ago #129307 by holch
Replied by holch on topic Random Question
I guess you are running into this problem described here:
pages.shanti.virginia.edu/polpsych/2012/...1/random-assignment/

Somehow the rand() function gets run again if the random number is generated on the same page as the following questions.

With something like that you can avoid this:
Code:
{if(is_empty(q1), rand(1,15), q1)}

Tried this code above with what I described before and it works as it is suposed to. Without the "is_empty", if you have the q1 and s1 to s15 questions on the same page you will run into trouble. If q1 with the rand()function is on a seperate page it should usually work just fine.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Last edit: 8 years 10 months ago by holch.
The following user(s) said Thank You: Thathekes_53133
The topic has been locked.
  • Thathekes_53133
  • Thathekes_53133's Avatar Topic Author
  • Offline
  • Banned
  • Banned
More
8 years 10 months ago #129308 by Thathekes_53133
Replied by Thathekes_53133 on topic Random Question
yes they are on the same page.

I think I found the problem. It seems that rand() was called each time I used q1. According to this thread I had to replace {rand(1,15)} by {if(q1>0,q1,rand(1,15))}. So q1 will be called once.

Now I have to see if it works by changing the presentation format to question-by-question.
The topic has been locked.
  • Thathekes_53133
  • Thathekes_53133's Avatar Topic Author
  • Offline
  • Banned
  • Banned
More
8 years 10 months ago #129309 by Thathekes_53133
Replied by Thathekes_53133 on topic Random Question
Yes, You are totally right. I just find out what really is going on!
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
8 years 10 months ago #129316 by DenisChenu
Replied by DenisChenu on topic Random Question
Alternative , it must work i think.

Add a group with only hidden question (first group). Then this queston are validated only one time (when starting survey).

Denis

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
  • holch
  • holch's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 10 months ago #129320 by holch
Replied by holch on topic Random Question
No, this isn't working.

Seems like when you call the result for this question the rand function is run again. Tested it here and the the rand equation gave me "3", when I moved to the next page, where the I display the result of the question in a text display I get a "2".

This is also in line with what Thomas White is writing in the thread that soheilj cited above:

The most likely reason is that the rand() function is called each time the page is visited AND each time it is validated.


I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • Thathekes_53133
  • Thathekes_53133's Avatar Topic Author
  • Offline
  • Banned
  • Banned
More
8 years 10 months ago #129323 by Thathekes_53133
Replied by Thathekes_53133 on topic Random Question

holch wrote: No, this isn't working.

Seems like when you call the result for this question the rand function is run again. Tested it here and the the rand equation gave me "3", when I moved to the next page, where the I display the result of the question in a text display I get a "2".

This is also in line with what Thomas White is writing in the thread that soheilj cited above:

The most likely reason is that the rand() function is called each time the page is visited AND each time it is validated.


This is Odd. This is working for me! Even on different pages! Did you change {rand(1,15)} to {if(q1>0,q1,rand(1,15))} or {if(is_empty(q1), rand(1,15), q1)}? It prevents rand() to be called twice.
The topic has been locked.
  • holch
  • holch's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 10 months ago #129325 by holch
Replied by holch on topic Random Question
Of course with is_empty and q1>0 it works, but even on the same page.

Denis suggested that an alternative would be to put the rand() question in a different group on a different page and this doesn't work (only if you use is_empty, etc., but as I said, when using this you don't need a different group or different page).

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose