Randomize but not repeat (1 Viewer)

JPaulo

Developer
Local time
Today, 05:08
Joined
Dec 21, 2009
Messages
185
Hi all;
That cod need not repeat the numbers.
How to not repeat ???

In module;

Code:
Public LançarAleatorio As Variant
Public NumAleatorio As Variant
 
Public Function GeradorNumerosRandomicos(X As Long, Y As Long) As Variant
On Error GoTo ErroLinha
Dim LNumAleatorio As Integer
Dim Llançar As Variant
LançarAleatorio = Format(Now(), "mm:ss")
LançarAleatorio = Replace(LançarAleatorio, ":", "")
Randomize (CInt(LançarAleatorio))
LNumAleatorio = Int((X - Y) * Rnd + Y)
GeradorNumerosRandomicos = LNumAleatorio
SaírLinha:
Exit Function
ErroLinha:
Select Case Err.Number
Case Else
MsgBox "Erro: " & Err.Number & " " & Err.Description, vbCritical, ""
GoTo SaírLinha
End Select
End Function

In my form;

Me.text1.Value=GeradorNumerosRandomicos(1, 60)
Me.text2.Value=GeradorNumerosRandomicos(1, 60)
Me.text3.Value=GeradorNumerosRandomicos(1, 60)
.... until text25
 

bulrush

Registered User.
Local time
Today, 00:08
Joined
Sep 1, 2009
Messages
209
You need to store each generated number in something like an array. Each time you generate a new number, look in your array of stored numbers. If the new number is in the array, generate a new number, otherwise use the new number.

I did this in Perl (customer wanted to generate unique but random ticket numbers so they couldn't be copied.) I used a hash to store my generated numbers.
 

JPaulo

Developer
Local time
Today, 05:08
Joined
Dec 21, 2009
Messages
185
Thanks for response;

Resolved.
 

JPaulo

Developer
Local time
Today, 05:08
Joined
Dec 21, 2009
Messages
185
Hi all;

I closed one more project.

Available for all.

Thanks
 

Attachments

  • Bingo_III.zip
    135.4 KB · Views: 80

Users who are viewing this thread

Top Bottom