Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input To Seed a Random Picker Answer (Amatts)

Status
Not open for further replies.

MajP

Technical User
Aug 27, 2005
9,382
US
Amatts,

I can not post to the original thread. I get a cold fusion error. So here is the answer to the Thread "Input To Seed a Random Picker"

I am a little confused on the thread because I wrote the original code cited. The whole purpose of the code was to avoid getting the same random sequence everytime you enter the database. The code was written to avoid the default behavior, which appears to be what you want. So instead of using myRandom you can just use Rnd.

Did you read the original thread? The whole issue was every time they opened the database they got the same pseudo list of cleaners selected.

If you use the Rnd function with a given seed pull the list, close the database, reopen the database, and pull the list again with the same seed you will get the same random list. So not sure what the issue here is.

You can also use this code

Code:
Option Explicit

Public ix As Integer
Public iy As Integer
Public iz As Integer
Public blnSeedSet As Boolean

Public Sub SetSeedRepeatable(SeedOne As Integer, SeedTwo As Integer, SeedThree As Integer)
  '    IX, IY and IZ should be set to integer values between 1 and
  '    30000 before the first entry.
  ix = SeedOne
  iy = SeedTwo
  iz = SeedThree
  blnSeedSet = True
End Sub

Public Function RepeatableRnd(Force As Variant) As Double
        Dim dx As Double
        Dim dy As Double
        Dim dz As Double
        Dim top As Double
        Dim tmp As Long
        Dim c1 As Double
        Dim c2 As Double
        Dim c3 As Double
        Dim l1 As Long
        Dim l2 As Long
        Dim l3 As Long
        Dim r1 As Long
        Dim r2 As Long
        Dim r3 As Long
        
        If Not blnSeedSet Then
           MsgBox "Seed Not Set"
           Exit Function
        End If
         l1 = 171
         l2 = 172
         l3 = 170
         r1 = 30269
         r2 = 30307
         r3 = 30323
         c1 = CDbl(r1)
         c2 = CDbl(r2)
         c3 = CDbl(r3)
         ix = (l1 * ix) Mod r1
         iy = (l2 * iy) Mod r2
         iz = (l3 * iz) Mod r3
         dx = CDbl(ix)
         dy = CDbl(iy)
         dz = CDbl(iz)
        
' Generate random uniform number
          top = ((dx / c1) + (dy / c2) + (dz / c3))
          tmp = Int(top)
          RepeatableRnd = top - tmp
    End Function

You then do not have to close the database to return a previous random list. You just have to reset the seed prior to calling the list.

You also have to be careful. Any subsequent calls to the function (such as a requery) without resetting the seeds will give another sequence.


 
I am a little confused on the thread
I think the thread is RedFlagged ...
Have a look at the statistics of the OP.
 
Oh. I thought if something got red flagged it got yanked. I may be misunderstanding what the OP is stating, but it seems this approach is not only a legitimate request but also the preferred verifiable method. If you were to be audited and someone asked to see how your random list was generated you would want to be able to show it and be able to repeat it. You can show the seeds used and how the list was created.

If the Company wants to target individuals this will be less immune to cheating because at least you can verify the seeds used and the list. If I use a non-repeatable list I can simply requery the list until I get the targets included. Then there is no way to verify that I did not "cheat" and target the individuals.
So in my mind saying this method is "immoral, illegal, blah, blah, blah" is silly and compeletely wrong. In truth it is more verifiable. However, either method can be cheated. But if some administrative processes are put in place (a witness verifying the entering of the seeds) the OPs proposed method is more verifiable.

Maybe I am misreading it, but it seems oppossitte of what the responders are saying.
 
MajP, it all looked like a big, sad, misunderstanding to me, and you may have grasped the truth. Being able to trace how something was done, and retrace the exact steps again, is often important.

There was one technical issue that bothered me. Is there any guarantee that the random number generator will remain the same in future versions of Access? Is it the same in all current versions anyway? If not, a method based on recreating from seeds will break.
 
In the past the VB rand function was shown to be a poor function. There was a lot written about it. Even then, the average user would never have seen an issue. However, if you are doing complex statistics, modeling, etc you would not use it. No one was going to use it for their doctoral thesis on probabilistic modeling of subatomic particles or a double blind study of a new cure for cancer.

In 2003 they finally updated it. It is about as good as it gets

The RAND function in earlier versions of Excel used a pseudo-random number generation algorithm whose performance on standard tests of randomness was not sufficient. Although this is likely to affect only those users who have to make a large number of calls to RAND, such as a million or more, and not to be a concern for almost every user, the pseudo-random number generation algorithm that is described here was first implemented for Excel 2003. It passes the same battery of standard tests.

The battery of tests is named Diehard (see note 1). The algorithm that is implemented in Excel 2003 was developed by B.A. Wichman and I.D. Hill (see note 2 and note 3). This random number generator is also used in the RAT-STATS software package that is provided by the Office of the Inspector General, U.S. Department of Health and Human Services. It has been shown by Rotz et al (see note 4) to pass the DIEHARD tests and additional tests developed by the National Institute of Standards and Technology (NIST, formerly National Bureau of Standards).

So I doubt you will see another change any time soon. But of note VB.net uses a Random class and interestingly

The implementation of the random number generator in the Random class is not guaranteed to remain the same across major versions of the .NET Framework. As a result, your application code should not assume that the same seed will result in the same pseudo-random sequence in different versions of the .NET Framework.

Almost all serious academic or corporate work using Random number generators would require you to be able to reproduce the random sequence so I found the responses and alarm curious.
 
For the rare occasions I want to do academic work with random numbers I use R, which offers a range of fully-documented algorithms (and R is just a matter of taste and cost; I'm sure all numerical packages offer much the same). I only use microsoft office random numbers for jobs similar to Amatts: sorting things into a reasonably random order that isn't unduly influenced by me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top