I am using Rnd() to generate a random number between 1 and 50 for a gaming database project I am working on. The code is activated by a Click event on a command button then the resulting value is passed to a text box for display. I added a "roll" simulator to loop through the numbers to try to give some "body" to a simple click. The problem is that every time the button is clicked after first opening the database the result is 36. It makes me loose faith in the pseudo-random nature of Rnd() if the recurring 36 is not the result of my neophyte coding. Might someone review this code and help me understand this phenomenon?
Let it be known, the Click event controls several other features of the form. However, for the sake of brevity, I am including the following code that applies to the function in question:
Code:
Private Sub cmdRandomGame_Click()
Dim GameNum As String
Dim RollSim As String
Dim WAIT As Double
GameNum = (1 + Int(50 * Rnd()))
'Use this to test
'GameNum = 13
'Trying to make random number change "visible" to user
RollSim = GameNum + 1
Do Until RollSim = GameNum
If RollSim > 50 Then
If GameNum = 1 Then
RollSim = 1
Else
RollSim = 1
Me.txtRandomCard = RollSim
WAIT = Timer
While Timer < WAIT + 0.01
DoEvents 'do nothing
Wend
RollSim = RollSim + 1
End If
Else
Me.txtRandomCard = RollSim
WAIT = Timer
While Timer < WAIT + 0.01
DoEvents 'do nothing
Wend
RollSim = RollSim + 1
End If
Loop
Me.txtRandomCard = GameNum
End Sub
As always, thanks in advance to the forum for your input.