Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:
  • Seite:
  • 1
  • 2

THEMA: using rand() and mandatory simultaneously

using rand() and mandatory simultaneously 1 Jahr 9 Monate her #91940

  • Anaben11
  • Anaben11s Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 6
  • Karma: 0
Hello,
my survey is supposed to show one randomly chosen question from a pool of 31 questions. This random question needs to be set on "mandatory".
The problem is that, if you answer the random question and click on the next-button to get forwarded to the next question group, the next question from the pool of now 30 remaining questions is asked. This continues until all questions are asked, instead of just one.

In the random question I use rand(1,31), the relevance equations for the other questions are set to randnumber.NAOK==x.

I asked this question already in the bug report area of this site, because I thought it was one, but I got one answer there: I was told to set the equation type question (thus the one with rand()) so that numbers are returned only ... well I did that, but it still just doesn't work, I have no idea how figure it out.

I use Version 2.00+ Build 130129

I attached the LSS file, if somebody wants to take a look at it.

I'd be very greatful for your help, I need to set up this survey for a thesis, it's really important to me :)

Thank you in advance!!

Dateianhang:

Dateiname: 445519_3101_0100_2013-01-31.lss
Dateigröße: 123 KB
Letzte Änderung: 1 Jahr 9 Monate her von Anaben11.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: using rand() and mandatory simultaneously 1 Jahr 9 Monate her #91952

  • DenisChenu
  • DenisChenus Avatar
  • OFFLINE
  • Moderator Lime
  • Beiträge: 6472
  • Dank erhalten: 854
  • Karma: 254
Hello,

Best is to use 2 group.

In the first:
Equation: rand(1,31)

In the second, you take the result of the equation to set the condition. If your user can not come back (option in survey), then no change.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: using rand() and mandatory simultaneously 1 Jahr 9 Monate her #91959

  • Anaben11
  • Anaben11s Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 6
  • Karma: 0
hey,
thanks for your reply. What do you mean exactly by taking the result of the equation to set the condition? How would you set up the second group?
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: using rand() and mandatory simultaneously 1 Jahr 9 Monate her #91972

  • tpartner
  • tpartners Avatar
  • ONLINE
  • LimeSurvey Team
  • Beiträge: 4297
  • Dank erhalten: 811
  • Karma: 374
If, for example, the question code for the Equation type question is "randNumber", then the relevance equations for the questions in group 2 would be:
randNumber.shown == 1
randNumber.shown == 2
randNumber.shown == 3
randNumber.shown == 4
......

If a question is hidden by relevance the mandatory requirement is overruled.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Letzte Änderung: 1 Jahr 9 Monate her von tpartner.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: using rand() and mandatory simultaneously 1 Jahr 9 Monate her #91976

  • DenisChenu
  • DenisChenus Avatar
  • OFFLINE
  • Moderator Lime
  • Beiträge: 6472
  • Dank erhalten: 854
  • Karma: 254
Yes: put the rand number in another group.

But here there are clearly a bug.
I reopen the bug tracker.

Alternative: with the same page, if your random questio code are RAND:
Put this in equation:
{if(RAND.NAOK, RAND.NAOK, rand(1, 9))}
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: using rand() and mandatory simultaneously 1 Jahr 9 Monate her #91977

  • TMSWhite
  • TMSWhites Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 759
  • Dank erhalten: 82
  • Karma: 36
This may not be a bug. Take a look at this older thread and this sample survey. In both cases, you have to check whether the random number has been assigned before calling rand() in order to prevent rand() from being called multiple times. That is actually the desired behavior of Expression Manager, which validates everything on both the client and server sides to avoid loss of data integrity.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: using rand() and mandatory simultaneously 1 Jahr 9 Monate her #91979

  • DenisChenu
  • DenisChenus Avatar
  • OFFLINE
  • Moderator Lime
  • Beiträge: 6472
  • Dank erhalten: 854
  • Karma: 254
Maybe,

But if you do:
1st equation question: RANDOM : {rand(1,100)}
2nd equation question: RETURN : {RANDOM}

You have different number at survey taking. Don't think it had to happen. After click on Next : OK, why not but not at page view.

Denis
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: using rand() and mandatory simultaneously 1 Jahr 9 Monate her #91982

  • mdekker
  • mdekkers Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 341
  • Dank erhalten: 68
  • Karma: 38
The reference to {RANDOM} causes the expression to be evaluated. The expression should make sure it only returns a random value when it was not already there so that even on reload of the page it stays the same.

From EM perspective this is completely correct. From the user point of view, it can be difficult. Maybe with the coming question plugins we can create a random number question that does exactly what most users want, only generate the number once and store it in db. For now I think the random needs to be documented in the wiki. There already is a sample survey, and maybe from the function list a pointer to the sample survey should be added. I will add that.
---
Menno Dekker
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: using rand() and mandatory simultaneously 1 Jahr 9 Monate her #91984

  • Anaben11
  • Anaben11s Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 6
  • Karma: 0
thanks so much guys!!
I implemented the solution with two question groups and it seems to work perfectly fine!!
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: using rand() and mandatory simultaneously 1 Jahr 9 Monate her #91985

  • DenisChenu
  • DenisChenus Avatar
  • OFFLINE
  • Moderator Lime
  • Beiträge: 6472
  • Dank erhalten: 854
  • Karma: 254
I completely understand at reload page OR at submit page.
But why at page view ?

Denis
Der Administrator hat öffentliche Schreibrechte deaktiviert.
  • Seite:
  • 1
  • 2
Moderatoren: ITEd
Ladezeit der Seite: 0.363 Sekunden
Donation Image