Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello to all!

 

I'm often playing on the lottery and I'm tired of making up numbers to cross so I came up with this little program.

It should produce a predetermined amount of random number sequences of predetermined lenght.

For instance 8 numbers from 1 to 39. It allways goes from 1.

I'm wondering am I doing this the right way and are these numbers "random enough" ? Or can I enhance my code somehow ?

Thanks!

 

Here is just a btn Click Event:

 

   Private Sub btnGen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGen.Click
       Dim niz() As Integer
       Dim br, arl, gg, i, j As Integer
       Dim dobitna As String
       Dim da As Boolean = False

       If Me.radio645.Checked Then
           If Me.chkSistem.Checked Then
               arl = Me.numUD.Value
           Else
               arl = 6
           End If
           gg = 45
       Else
           If Me.chkSistem.Checked Then
               arl = Me.numUD.Value
           Else
               arl = 7
           End If
           gg = 37
       End If

       For j = 0 To CInt(Me.txtBK.Text) - 1

           ReDim niz(arl - 1)

           For i = 0 To arl - 1
               Do Until da
                   Randomize()
                   br = CInt(Int((gg * Rnd()) + 1))
                   If niz.IndexOf(niz, br) = -1 Then
                       niz(i) = br
                       da = True
                   End If
               Loop
               da = False
           Next

           niz.Sort(niz)

           For i = 0 To arl - 1

               Select Case i
                   Case 0
                       dobitna = CStr(niz(i))
                   Case arl - 1
                       dobitna = dobitna & "," & vbTab & CStr(niz(i)) & vbTab & vbTab & vbTab & vbTab
                   Case Else
                       dobitna = dobitna & "," & vbTab & CStr(niz(i))
               End Select

           Next

           If j = 0 Then
               Me.listK.Items.Add("")
               Me.listK.Items.Add("----------------------------------------------------------------------")
               Me.listK.Items.Add(dobitna.ToString)
           Else
               Me.listK.Items.Add(dobitna.ToString)
           End If

           niz.Clear(niz, 0, arl)
           dobitna = ""

           If (j + 1) Mod 8 = 0 Then
               'Me.listK.Items.Add("")
               'Me.listK.Items.Add("----------------------------------------------------------------------")
               Me.listK.Items.Add("----------------------------------------------------------------------")
               Me.listK.Items.Add("")
           End If

       Next

   End Sub

Posted

I was putting it together from scratch and I never worked in VB6. I'm doing some ASP so maybe the string operations could be better but these worked and I fine with it for now.

I'll look into Random!

Thanks

  • *Experts*
Posted

How much do you spend on the lottery? Send me half that amount and once a year I'll send you back $5. You should come out about $5 ahead that way... :)

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...