Hi, I want random numbers for the questions I used random function in asp.net but repeats the question. How do I get repetitive questions? C#. Thank you.
The problem with random is often the following:
The following codes are often used A lot will return to the 'non-random' sequence
for (int j = 0; j & lt; 100; j ++) {random random = new random (); Int i = rnd.Next (1, 5); Console.WriteLine (i); } One more of the following random numbers will be distributed:
random rnd = new Random (); {Int i = rnd.ext (1, 5) for (int j = 0; j & lt; 100; j ++); Console.WriteLine (i); } A different approach to generate a random number can be obtained by Linq:
var randomNumber = Enumerable.Range (1, 10). OrderBe (G = & gt; Guid.NewGuid ()). first (); This method first creates a list of numbers (1 to 10 in this example), and after that the list of orders creates a guide to manipulate this list so that first () random Be like I often rely on this method to get a random number instead of using random classes.
UPDATE Assume that you want 10 unique random numbers to list 100 random numbers. Using linak-expression that you will:
list & lt; Int & gt; 10RandomNumbers = Noteworthy. Ranges (1, 100). OrderBe (G = & gt; Guid.NewGuid ()) Take. (10); You should now be able to go through the list Ten RandomNumbers .. They should be unique and random. UPDATE 2 Take a look at this explanation. Take the Intuit method:
The above code will return a list of randomly selected 10 numbers from the collection of 100 numbers.
What you just want to do next is:
foreach (int i in ten domain) {// int to bring your question based on Code} Hope this helps
Comments
Post a Comment