Created
October 2, 2013 12:48
-
-
Save mikakolari/6793147 to your computer and use it in GitHub Desktop.
Get random numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int[] getRandoms(int count, int max) | |
{ | |
int[] results = new int[count]; | |
var mask = new BitArray(max + 1); | |
int counter = 0; | |
while (counter < count) | |
{ | |
int r = random.Next(max + 1); | |
if (!mask[r]) | |
{ | |
results[counter] = r; | |
mask[r] = true; | |
counter++; | |
} | |
} | |
return results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment