My first app in 30 years ... how logically bad is it?
Lame lotto number generator but found it interesting enough to motivate me to code again ... lol. I would think there is a better way to check for duplicates and an easier way to display each 'ball' number into a different label. Thanks to any who might spend a moment to look this over
Lame lotto number generator but found it interesting enough to motivate me to code again ... lol. I would think there is a better way to check for duplicates and an easier way to display each 'ball' number into a different label. Thanks to any who might spend a moment to look this over
Code:
// Initialize variable to point to each number in the array
int m = 0;
// Loop until 5 random numbers have been generated and assigned to the array
for (int i = 0; i < mmar.Length; i++)
{
// create arrays to utilize higher probablistic ranges for each ball
int[] y = new int[5] { 1, 3, 8, 18, 30 };
int[] z = new int[5] { 21, 31, 52, 63, 71 };
// use the for loop's initialized variable to change random range
mmnum = mmball.Next(y[i], z[i]);
// Loop to ensure each number is unique
for (int j = 0; j < mmar.Length; j++)
{
// check the number of ball for duplicates
if(mmnum == mmar[j])
{
// if not unique create new ball
mmnum = mmball.Next(1, 71);
// re-initialize to ensure new ball number is unique
j = 0;
}
}
// put the ball number into our array
mmar[m] = mmnum;
// change to new array slot
m++;
}
// Sort the numbers in the array before displaying them
Array.Sort(mmar);
// OLD ... START Place lotto numbers on screen
num1mm.Text = mmar[0].ToString();
num2mm.Text = mmar[1].ToString();
num3mm.Text = mmar[2].ToString();
num4mm.Text = mmar[3].ToString();
num5mm.Text = mmar[4].ToString();