dizzy_boy Posted September 8, 2004 Posted September 8, 2004 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 Quote
Administrators PlausiblyDamp Posted September 8, 2004 Administrators Posted September 8, 2004 You may want to consider using the .Net Random class rather than the legacy VB6 Rnd function. (Just out of interest is this a port from VB6 as there is a lot of legacy constructs in there). Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
dizzy_boy Posted September 8, 2004 Author Posted September 8, 2004 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 Quote
samsmithnz Posted September 8, 2004 Posted September 8, 2004 I agree use the Random namespace, also use the time as a seed, so that each time you generate numbers you'll get a different combination. Quote Thanks Sam http://www.samsmith.co.nz
*Experts* Nerseus Posted September 9, 2004 *Experts* Posted September 9, 2004 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 Quote "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
ToniMontana Posted September 9, 2004 Posted September 9, 2004 You are right, Nerseus. Lottery is ****! (oh, that word is censored...) ;-) Quote Greetings, Toni.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.