Skip to content

Instantly share code, notes, and snippets.

@mikakolari
Created October 2, 2013 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikakolari/6793147 to your computer and use it in GitHub Desktop.
Save mikakolari/6793147 to your computer and use it in GitHub Desktop.
Get random numbers
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