Created
July 25, 2014 19:04
-
-
Save dgkanatsios/0671874a38e728b4929e to your computer and use it in GitHub Desktop.
Get random numbers given a margin around a particular one
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 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