Lottery Number Picker (Uses Random and Array)






2.13/5 (7 votes)
Aug 19, 2002

102881
A small little program that randomly picks six numbers and display the top six picked
Introduction
This program cycles through numbers 1-49 randomly c number of times. It then displays the top six picked numbers, in order. The Random is as random as possible, because it starts the cycle according to the computers millisecond clock. This may not be of much help to advanced programmers, but I think it's a neat little program.c=1000; int[] numb = new int[c]; DateTime dt = new DateTime(); dt = DateTime.Now; Random rnd = new Random(dt.Millisecond); for (int i=0; i<c; i++) { numb[ i ] = rnd.Next(1,49); } Array.Sort(numb); int k=0; int j=0; int[] length = new int[50]; int[] result = new int[50]; for (int i=0; i<c-1; i++) { if (numb[ i ] == numb[i+1]) { result[k] = numb[ i ]; length[k] = j+=1; } else { k+=1; j=0; } } Array.Sort(length, result); txtNum1.Text = result[49].ToString(); txtNum2.Text = result[48].ToString(); txtNum3.Text = result[47].ToString(); txtNum4.Text = result[46].ToString(); txtNum5.Text = result[45].ToString(); txtNum6.Text = result[44].ToString();