Skip to content

Instantly share code, notes, and snippets.

@dgkanatsios
Created July 25, 2014 19:04
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 dgkanatsios/0671874a38e728b4929e to your computer and use it in GitHub Desktop.
Save dgkanatsios/0671874a38e728b4929e to your computer and use it in GitHub Desktop.
Get random numbers given a margin around a particular one
public static List<int> GetRandomNumbersAroundCorrectOne(int correctOne, int margin, int count)
{
List<int> results = new List<int>();
for (int i = 0; i < count; i++)
{
//get the prosimo
int prosimo = 1;// ((NextRandom(1, 3) % 2) == 0) ? 1 : -1;
int number;
if (prosimo == 1)
{
number = SharedUtilities.NextRandom(correctOne + 1, correctOne + 1 + margin);
}
else
{
number = SharedUtilities.NextRandom(correctOne - 1 - margin, correctOne - 1);
}
if (results.Contains(number))
{
i--;
continue;
}
else results.Add(number);
}
return results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment