Click here to Skip to main content
Licence 
First Posted 18 Aug 2002
Views 79,294
Bookmarked 15 times

Lottery Number Picker (Uses Random and Array)

By | 18 Aug 2002 | Article
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.


<BOLD>
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();
</BOLD>


How it works

It may be a little confusing, but here's the gist of it. Starting by the computers millisecond, numbers 1-49 are cycled through. They are then stored in an array, and sorted by number (lowest to highest). Then the second loop determines how many times a number appears in the array, that number is stored in another array and sorted (number appearing the least to number appearing the most). Then the lost six numbers of the array are displayed (being the six most picked)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Zachery

Web Developer

United States United States

Member

"..Been walking the earth since child-birth. I never went to school, and when I did I ate my homework. Never played it cool, and if I did I was a poser. You can't blame a nerd for trying to get closer. Now I'm the poster boy for geeks and freaks..."
 
My profile according to Google
 
I like tha moon
 
All Your Base Are Belong To Us
 
Think different, think beige.
 
Domopers
 
Disclaimer:

Any and all things I say, I in no way think myself better then anyone else. I have my fair share (well, a good deal) of problems. I just like to gripe whenever given the chance


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralCycles 1000 Pinmembermrhassell16:18 14 Feb '09  
GeneralLotto PinmemberHuseyin Altindag1:19 30 Apr '07  
Generalcute.. Pinmemberf27:02 13 Oct '04  
Questionplacing random numbers into an array? Pinsussmanners10:03 19 Nov '02  
AnswerRe: placing random numbers into an array? PinmemberChristian Graus10:32 19 Nov '02  
GeneralMake it real! PinmemberPhilip Fitzsimons4:41 20 Aug '02  
GeneralProgram PinmemberZachery4:32 20 Aug '02  
GeneralDid you?! PinsussAnonymous4:11 20 Aug '02  
GeneralRe: Did you?! PinsussAnonymous11:35 14 Jul '05  
GeneralIt doesn't pick winning numbers! PinmemberDavid Wulff4:10 20 Aug '02  
GeneralRe: It doesn't pick winning numbers! PinadminChris Maunder4:27 20 Aug '02  
GeneralRe: It doesn't pick winning numbers! PinmemberMauricio Ritter5:43 20 Aug '02  
GeneralRe: It doesn't pick winning numbers! PinmemberChristian Graus10:34 19 Nov '02  
GeneralRe: It doesn't pick winning numbers! PinmemberENewton11:05 1 Dec '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 19 Aug 2002
Article Copyright 2002 by Zachery
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid