Welcome to the LimeSurvey Community Forum

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

Random number generator - no repeated numbers

  • user18
  • user18's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 8 months ago #217737 by user18
Hi everyone. I am new to LimeSurvey and do not have much coding experience.

I am trying to modify the following code used on another forum post to create 10 (min 1 max 10) randomly generated numbers that do not repeat. This is the original blog post:  forums.limesurvey.org/forum/can-i-do-thi...ame-randnumber-twice . I was able to edit the code so that more than 2 random numbers are generated, but how can I edit the if statement so that none of the additional numbers repeat?
 
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 8 months ago #217739 by tpartner
Replied by tpartner on topic Random number generator - no repeated numbers
There should be no repeats, the if statement only checks if the inputs are already populated.

How many inputs do you have? What is your code?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • user18
  • user18's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 8 months ago #217740 by user18
I misunderstood the purpose of the if statement, so I had been focusing on it in order to solve the issue with the repeating numbers. But after you explained it, I found the error elsewhere in my code. Thank you!!
The topic has been locked.
  • user18
  • user18's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 7 months ago #218660 by user18
Hi Tony,

Thank you for your help last month. I have a quick followup question. I have used this code several times in my survey and there is one section that I would like to change to allow the numbers to repeat. Is there a modification I can do to the original code to allow the numbers to repeat?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 7 months ago #218667 by tpartner
Replied by tpartner on topic Random number generator - no repeated numbers
No, that script can only provide unique numbers. If you don't care about repeats, simply us the ExpressionScript rand() function to load the numbers.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • user18
  • user18's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 7 months ago #218778 by user18
Thank you so much. You have been so helpful.

I have been able to get all of the randomization to work. However, I do not want participants to see the page which generates all of the random numbers. I tried to hide each question using the "Always hide this question" in the "Display" section, but I think this stops the random numbers from generating because the text that should appear later in the survey does not show anymore. What can I do so that the random numbers are generated but not shown to participants?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 7 months ago #218779 by tpartner
Replied by tpartner on topic Random number generator - no repeated numbers
Assign those questions a CSS class "hidden".

- manual.limesurvey.org/Question_type_-_Mu...lass_.28css_class.29

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • user18
  • user18's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 7 months ago #218781 by user18
I tried this and it hides the generator but leaves blank pages which the respondent must click through. Is there a way to do this where it does not show these pages to the respondent at all?
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 7 months ago #218782 by holch
No, you should put these hidden questions on other pages together with other questions. Using Group-by-Group and use the Groups as if they were pages. If you go question per question, then there will be always empty pages.

We generally recommend to use the group by group mode, because it gives you the chance to be more flexible and put more than one question on a 'page' or just one question as well. It is more work because you probably need more groups, but there is no other way in LS to create "pages" with more than one question than going group by group. And even if you don't want to show these questions you still need to place them.

If you use the "always hide" option the gui you don't need that, but then you can't use these hidden questions for Javascript, etc.

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: tpartner
The topic has been locked.
  • user18
  • user18's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 7 months ago #218788 by user18
Thank you!
The topic has been locked.
  • user18
  • user18's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 5 months ago #220785 by user18
Hi again! I have another follow-up question so I thought I would write it here for continuity. After initial feedback from the survey, I made some changes to the number of treatments, format, etc. and now the non-repeating random number generator does not load when the page loads. However, when I make the question mandatory and then try to complete the survey, I get an error message that I did not fill out a mandatory question and then the page loads the random numbers and I can continue. Do you know what could be causing this issue?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 5 months ago #220793 by tpartner
Replied by tpartner on topic Random number generator - no repeated numbers
LimeSurvey version?

Can you attach a small sample survey (.lss file) containing only the relevant questions?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose