The problem I'm having is that I can't believe my results. There's no realistic way that it would generate the same number 100 times in a row...but I keep getting that result or a result that leads me to believe there are only 2 values getting created.
If someone would be so kind as to review my code and point out where I might have gone wrong, I'd appreciate it.
static void RandomWindow()
{
List<int> randomNumList = new List<int>();
int evenCount = 0;
for (int i = 0; i < 100; i++)
{
Random random = new Random();
int nums = random.Next(0, 1000);
randomNumList.Add(nums);
}
randomNumList.Sort();
int countTotal = randomNumList.Count;
int smallest = randomNumList[0];
int largest = randomNumList[99];
for (int j = 0; j < randomNumList.Count; j++)
{
if (randomNumList[j] % 2 == 0)
evenCount++;
}
string result = "";
result += "Even Numbers: \t" + evenCount
+ "\nTotal Entries: \t" + countTotal
+ "\nSmallest number: \t" + smallest
+ "\nLargest number: \t" + largest
+ "\nRange of numbers: \t" + smallest + " <-> " + largest;
MessageBox.Show(result, "Information about 100 Random Numbers", MessageBoxButtons.OK);
}

New Topic/Question
This topic is locked




MultiQuote




|