Results 1 to 3 of 3

Thread: Help with lottery game code plss

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2018
    Posts
    1

    Help with lottery game code plss

    Beginner programmer here, I need to code a console application program that is a random lottery number generator that allows users to randomly generate 7 random lottery numbers using 2 functions called in main. I am having troubles with my functions and calling them to main. Can anyone help? My code is:

    Code:
    Module Module1
    
    Sub Main()
    Const intMax_SUBSCRIPT As Integer = 7
    Dim intnumbers(intMax_SUBSCRIPT) As Integer
    Dim winningNumbers As Integer
    Dim makeNumbers As Integer
    
    makeNumbers = showNumbers(intnumbers)
    winningNumbers = showNumbers(intnumbers)
    
    
    
    
    End Sub
    
    Public Function showNumbers(ByRef array() As Integer) As Integer
     Dim antCount As Integer
     Dim total As Integer = 0
     'Create a random object
     Dim rand As New Random
    
     For antCount = 0 To array.Length - 1
      total = rand.Next(0, 10)
    
      Console.WriteLine("Your seven digit lottery number is: " & total)
     Next
    
     Return total
    End Function
    
    Public Function showWinner(ByRef array() As Integer) As Integer
     Dim intCount As Integer
     Dim total As Integer = 0
    
    
      For total = 0 To array.Length - 1
    
    
      Next
    
     Return total
    End Function
    End Module
    Last edited by Shaggy Hiker; Apr 21st, 2018 at 10:08 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Help with lottery game code plss

    Just for future reference, I know I'm not alone in being annoyed by the use of things like "plss" and "plz". It probably shouldn't matter and it doesn't much, but it does some. If you want to say "please" then you should say "please". It's two extra keystrokes over what you did type. Anything that makes it less likely that you'll get help is a bad thing, so I'd suggest that using text speak in a forum with no character limit is a bad thing.

    As for the issue, what is it? You say:
    I am having troubles with my functions and calling them to main.
    What are those troubles? Please (see what I did there ) explain what you're trying to achieve and exactly how what you're doing is failing to achieve it. Maybe we could work it out from the code and maybe not, but I don't read code if I haven't already had it explained what I'm looking for in it.

    That said, I have posted a couple of threads in the CodeBank forum that may be of use to you. You can access then via the link in my signature below. There is one about Unique Random Selections From A List and there is another about Randomising a List. You could use either in your case. The first one creates a list of all the possible values, selects one at random and then removes that from the list. That sounds awfully like a lottery draw. The second one creates a list, randomises it and then you can take the items in order from the list and they will be effectively random. That's much like shuffling a deck of cards and then dealing.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Help with lottery game code plss

    Your loop has some problems. One thing that isn't a problem, currently, but is still a good idea is that you should declare the Random object at module scope rather than within a method as you have done. The reason for this has to do with how random number generators are seeded. If you create them too fast, you won't get random numbers. That could be an issue here. If that ShowNumbers() method gets called too fast you'd end up with just one number.

    You end up with just one number anyways, because of an error in the loop. I'm not sure exactly where the error is, because I'm not quite sure what you want to be doing with the array, and what the Total variable is used for. If you are creating a lottery number, the total doesn't matter to anybody. As it stands, though, you iterate through a loop that happens to be the size of the array, but you aren't putting the numbers into the array, you just keep replacing the value in Total over and over and over, so what finally gets returned is nothing more than Total, which by then holds the last value that was put into the variable.

    It kind of looks like you were thinking that you could just generate seven random digits and concatenate them by some means, but integers don't work that way. I stall can't understand what the array is for, but even if you meant to concatenate seven digits together, you have a problem because you could generate a 0 as the first digit, which will be removed from an integer. You could concatenate seven characters into a string, but that doesn't explain the array. Alternatively, you could also just generate a random number between 0 and 10000000, but you'll get repeated digits.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width