The code below generates a seed value and 3 random numbers that appear in the immediate window when the code is run. Instead of having the number 3 hard coded, I'd like to have a form where I could select the number random numbers I'd like to choose and then create a table or query which would hold the Seed number in one column and the random numbers in another column. Then I would create a report so I could have a printout of the results. Anyone know how to do this?
Thanks
Option Compare Database
Function GetRandomBetween(ByVal lngMin As Long, ByVal lngMax As Long) As Long
On Error GoTo ErrHandler
GetRandomBetween = Fix((lngMax - lngMin + 1) * Rnd + lngMin)
ExitHere:
Exit Function
ErrHandler:
Debug.Print Err, Err.Description
Resume ExitHere
End Function
Function SeedRandomizer() As Long
Dim lngSeed As Long
Const MIN = 1
Const MAX = 2147483647
'this should do it
Randomize Timer()
'get a random seed value between min and max
lngSeed = GetRandomBetween(MIN, MAX)
'get a random sign value
If GetRandomBetween(1, 2) = 1 Then
lngSeed = -lngSeed
End If
'randomize using the new seed
Randomize lngSeed
'return the seed value
SeedRandomizer = lngSeed
End Function
'CODE
Sub Get3Randoms()
Dim i As Integer
Debug.Print "Seed Value: " & SeedRandomizer
For i = 1 To 3
Debug.Print "Random " & i & ": " & GetRandomBetween(1, 9999999)
Next i
End Sub
Thanks
Option Compare Database
Function GetRandomBetween(ByVal lngMin As Long, ByVal lngMax As Long) As Long
On Error GoTo ErrHandler
GetRandomBetween = Fix((lngMax - lngMin + 1) * Rnd + lngMin)
ExitHere:
Exit Function
ErrHandler:
Debug.Print Err, Err.Description
Resume ExitHere
End Function
Function SeedRandomizer() As Long
Dim lngSeed As Long
Const MIN = 1
Const MAX = 2147483647
'this should do it
Randomize Timer()
'get a random seed value between min and max
lngSeed = GetRandomBetween(MIN, MAX)
'get a random sign value
If GetRandomBetween(1, 2) = 1 Then
lngSeed = -lngSeed
End If
'randomize using the new seed
Randomize lngSeed
'return the seed value
SeedRandomizer = lngSeed
End Function
'CODE
Sub Get3Randoms()
Dim i As Integer
Debug.Print "Seed Value: " & SeedRandomizer
For i = 1 To 3
Debug.Print "Random " & i & ": " & GetRandomBetween(1, 9999999)
Next i
End Sub