Programa em Visual Basic para gerar os números do Totoloto
Carregue aqui para experimentar este programa
Option Explicit Private Sub troca(ByRef a, ByRef b) Dim aux As Integer aux = a a = b b = aux End Sub Private Sub ordena(ByRef loto) Dim i As Integer, j As Integer For i = 1 To 5 For j = i + 1 To 6 If loto(i) > loto(j) Then Call troca(loto(i), loto(j)) End If Next Next End Sub Sub totoloto() Dim loto(1 To 6) As Integer Dim saco(1 To 49) As Integer Dim i As Integer, ale As Integer, max As Integer Dim resposta As String Randomize For i = 1 To 49 saco(i) = i Next max = 49 For i = 1 To 6 ale = Int(Rnd() * max + 1) loto(i) = saco(ale) saco(ale) = saco(max) max = max - 1 Next Call ordena(loto) resposta = "" For i = 1 To 6 resposta = resposta & Str(loto(i)) & " " Next MsgBox (resposta) End Sub Private Sub CommandButton1_Click() Call totoloto End Sub