How to generate a random number without repeating
Question
Service Studio Version
11.14.14 (Build 59923)

Hi, i'm having slight problem generating random numbers from a Lenght of a List of questions and guaranteeing they don't repeat, or my randomly generated exam might have repeated questions.

So i can generate a random number from a Question.Length list and after I append that question to a local variable.
But before i create the exam with the CRUD i need to check that in that list there aren't repeating questions.

Any idea that might help?

Thanks you

You could first have a variable of type list of questions where you would make a ListAppend to add to it only the questions that have already been used. Then you would make a condition (with foreach) where you would check if the questions for the next exam are in the previous list - if so, skip them, allowing only the ones that would not have been used. 

Hi @Diogo E Filipe ,

You can also use ListIndexOf to check if the question already exists on your local variable list. It will return -1 if there's no repeated question, and you could do this before appending to the local variable

Hi @Diogo E Filipe

The easiest and fastest way code-wise is just using the ListDistinct action on that variable, before starting the exame, passing your list as input, and it will return your list without repeated values!!!

Let me know if this helped!
Cheers,
Paulo

There is a similar question already posed, this is a good reply with resources to use:

https://www.outsystems.com/forums/discussion/50411/how-to-generate-random-string-and-integer-in-server-action/#Post187075

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.