Random number generator - no repeated numbers

More
2 months 3 weeks 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?
 

Please Log in to join the conversation.

More
2 months 3 weeks ago #217739 by tpartner
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.

Please Log in to join the conversation.

More
2 months 3 weeks 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!!

Please Log in to join the conversation.

More
1 month 3 weeks 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?

Please Log in to join the conversation.

More
1 month 3 weeks ago #218667 by tpartner
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.

Please Log in to join the conversation.

More
1 month 2 weeks 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?

Please Log in to join the conversation.

More
1 month 2 weeks ago #218779 by tpartner
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.

Please Log in to join the conversation.

More
1 month 2 weeks 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?

Please Log in to join the conversation.

More
1 month 2 weeks 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

Please Log in to join the conversation.

More
1 month 2 weeks ago #218788 by user18
Thank you!

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now