Maximum number in Array of Random Numbers
Make an array of generated random numbers and get the maximum number every time you run.
Source
private static Random random = new Random();
public static int MaxArrayRandomNumber(this int[] array)
{
int maxnumber = array[0];
if (array is null) { return 0; }
else
{
for (int i = 0; i < array.Length; i++)
{
array[i] = random.Next();
}
for (int i = 0; i < array.Length; i++)
{
maxnumber = Math.Max(maxnumber, array[i]);
}
}
return maxnumber;
}
Example
int[] arr = new int [5];
Console.WriteLine(arr.MaxArrayRandomNumber());