ho trovato questo codice in rete che praticamente non fà altro che generare dei numeri casuali.
il punto è questo:
è possibile escludere dei numeri nel processo di generazione magari separati da ","?
codice:Dim NSest(0 To 5) As Byte 'Array rappresentante la sestina Function diverso() As Boolean Dim i1 As Byte Dim j1 As Byte diverso = True For i1 = 0 To 4 For j1 = i1 + 1 To 5 If NSest(i1) = NSest(j1) Then diverso = False Exit Function End If Next Next End Functioncodice:Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim i, j As Byte Dim app As Byte Dim r As New Random(CInt(Date.Now.Ticks And Integer.MaxValue)) Application.DoEvents() For i = 0 To 5 NSest(i) = r.Next(1, 90) Next Do For i = 0 To 4 For j = i + 1 To 5 If NSest(i) = NSest(j) Then Do NSest(j) = r.Next(1, 90) Loop Until NSest(i) <> NSest(j) End If Next Next Loop Until diverso() = True For i = 0 To 4 For j = i + 1 To 5 If NSest(i) > NSest(j) Then 'Ordino i numeri in ordine crescente app = NSest(i) NSest(i) = NSest(j) NSest(j) = app End If Next Next 'assegno alle 6 label i numeri ottenuti lblN1.Text = NSest(0) lblN2.Text = NSest(1) lblN3.Text = NSest(2) lblN4.Text = NSest(3) lblN5.Text = NSest(4) lblN6.Text = NSest(5) If Lbltempo.Text = TextBox1.Text Then Timer1.Stop() Lbltempo.Text = 0 Timertempo.Stop() End If End Sub

Rispondi quotando