c# - Get a unique number -
For the school, I need to create a project in C # which will ask 20 questions randomly.
I is a text file containing answers questions.
With some code we put questions in an array. Now we can make a number from 0 to 19 (20 questions). But every question must be seen only 1 time and 1 time.
We can not do random first and in the next order. Each question should be random.
My code (in Dutch):
Public Inc. Random VraagMaker () {int num; Random Random = New Random (); Num = randNum.Next (0, 19); For (int i = 0; i
You can create a list of all your questions, and then randomly You can ask questions from:
// Use a list & lt; String & gt; Question or list & lt; Int & gt; Index T Remove Questionental Question & lt; T & gt; (List & lt; T & gt; question, random random) {// TODO: add verification (i.e .:: question is not empty, has at least 1 element, etc.) int index = random.Next (questions.Count); T question = question [index]; Questions.RemoveAt (index); Return question; } In this way, you can build the list (in any number), and only remove those people you say.
Comments
Post a Comment