Is it possible to create a random number from a selection of numbers in c#.
For example I have an array of numbers from 1-90 and once a number has been called a propery of that number changes. I therefore only want to generate the numbers where that property has not changed. This will therefore only randomly call the numbers between 1 and 90 one.
I have done this using a loop but just wanted a quiker and cleaner method if possible.
My current code is:
public object GenerateNumber()
{
bool alreadyCalled = false;
while (!alreadyCalled)
{
Random randomNumber = new Random(System.DateTime.Now.Millisecond);
int RandomNumberCalled = randomNumber.Next(1, 91);
if (Numbers.ToList().Find(x => x.Number == RandomNumberCalled).IsCalled != null)
{
// change number to is called and do other things.
}
}
return false;
}