Let’s say we have this numbers 51,53,58,60,78. How can we select a number randomly in such a way if its already selected/picked, it will not be selected in the next run.
Also, after all numbers are selected, everything is restarted and the process repeats itself.
Load your integers into an array. Create an instance of the
Randomclass. Call theRandom.Next(int minValue, int maxValue)method with0being the minValue, and your array count minus 1 being your maxValue. Then use that random integer to reference your integer array.Edit: for non repeating data, just store the index that was already use of the integer array in a separate list and prior to utilizing the random number, do a check on the list to see if it was already used. If so, then re-run the random number code. If it is full, then don’t allow that to continue in an endless loop.