Is it possible to create a random number from a set of numbers in C #.
For example, I have an array of numbers from 1-90 and after the number has been called the property of this number. Therefore, I want to generate numbers in which this property has not changed. Therefore, it will randomly call numbers from 1 to 90 units.
I did this using a loop, but if possible, I just wanted to use the Quiker and Cleaner method.
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)
{
}
}
return false;
}
Bruie source
share