This problem involves generating random numbers with a user supplied seed number. In this
example, I have 3 different dollar ranges and a sample size for each dollar range.
Dollar Range...................Sample Size.................Seed#
.01 - 10000............................ 417.....................777
10000.01-75000..................... 200.....................555
75000.01 - 9999999999...........100.....................999
I am trying to seed them individually but the first seed seems to control all results. For
example, If I change the seed in the .01-10000 dollar range from 777 to 888, the numbers chosen
in the other two ranges are changing even though they shouldn't because their seeds remain the
same. This is the query and the module I'm using.
(SELECT DISTINCTROW TOP 417 tblAmount.Amt FROM tblAmount WHERE Amt between 00.01 and 10000.00 GROUP BY tblAmount.Amt, tblAmount.ID, GetRan(777,[id]) ORDER BY GetRan(777,[id]))
UNION ALL (SELECT DISTINCTROW TOP 200 tblAmount.Amt FROM tblAmount WHERE Amt between 10000.01 and 75000.00 GROUP BY tblAmount.Amt, tblAmount.ID, GetRan(555,[id]) ORDER BY GetRan(555,[id]))
UNION ALL (SELECT DISTINCTROW TOP 100 tblAmount.Amt FROM tblAmount WHERE Amt between 75000.01 and 99999999.99 GROUP BY tblAmount.Amt, tblAmount.ID, GetRan(999,[id]) ORDER BY GetRan(999,[id]));
Option Compare Database
Public gblnInitialized As Boolean
Public Function GetRan(Seed As Long, nextnum) As Double
If gblnInitialized = False Then
InitializeRandom (Seed)
End If
GetRan = Rnd(nextnum)
End Function
Public Sub InitializeRandom(Seed As Long)
Rnd -1
Randomize Seed
gblnInitialized = True
End Sub
Any suggestions how to accomplish what I'm trying to do?
Thanks
example, I have 3 different dollar ranges and a sample size for each dollar range.
Dollar Range...................Sample Size.................Seed#
.01 - 10000............................ 417.....................777
10000.01-75000..................... 200.....................555
75000.01 - 9999999999...........100.....................999
I am trying to seed them individually but the first seed seems to control all results. For
example, If I change the seed in the .01-10000 dollar range from 777 to 888, the numbers chosen
in the other two ranges are changing even though they shouldn't because their seeds remain the
same. This is the query and the module I'm using.
(SELECT DISTINCTROW TOP 417 tblAmount.Amt FROM tblAmount WHERE Amt between 00.01 and 10000.00 GROUP BY tblAmount.Amt, tblAmount.ID, GetRan(777,[id]) ORDER BY GetRan(777,[id]))
UNION ALL (SELECT DISTINCTROW TOP 200 tblAmount.Amt FROM tblAmount WHERE Amt between 10000.01 and 75000.00 GROUP BY tblAmount.Amt, tblAmount.ID, GetRan(555,[id]) ORDER BY GetRan(555,[id]))
UNION ALL (SELECT DISTINCTROW TOP 100 tblAmount.Amt FROM tblAmount WHERE Amt between 75000.01 and 99999999.99 GROUP BY tblAmount.Amt, tblAmount.ID, GetRan(999,[id]) ORDER BY GetRan(999,[id]));
Option Compare Database
Public gblnInitialized As Boolean
Public Function GetRan(Seed As Long, nextnum) As Double
If gblnInitialized = False Then
InitializeRandom (Seed)
End If
GetRan = Rnd(nextnum)
End Function
Public Sub InitializeRandom(Seed As Long)
Rnd -1
Randomize Seed
gblnInitialized = True
End Sub
Any suggestions how to accomplish what I'm trying to do?
Thanks