in reply to Re: Check randomly generated numbers have not been used before
in thread Check randomly generated numbers have not been used before

This appears to be a Linear congruential generator for which the multiplier parameter a = 1. I'm far and far from being a PRNG expert (I'd bet BrowserUk could write a lengthy article on this topic before his first mug of caffeine-delivery-beverage-of-choice in the morning), but I think you need to exercise some caution in chosing the m a c parameters so that the period of the generator is maximized (i.e., equal to m) and the generator never gets "stuck" at a particular value of Xn. See the linked article. Just glancing at this article, I don't see any case in the "Parameters in common use" table of a = 1, so this may be a red flag.

Update: After more thought (and looking at pryrt's post), a multiplier a = 1 does seem to meet all the requirements for maximum period length for this type of PRNG, but gives a boring "clock" progression to the output, i.e., the output always advances by the offset mod S. Don't you want the output to bounce around a bit more and at least seem more random? ;)


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^3: Check randomly generated numbers have not been used before
by pryrt (Abbot) on Sep 16, 2016 at 18:49 UTC
    In Xn+1 = (a*Xn + c) (mod m): If the offset c is relatively prime with m, you will generate a maximal-length sequence. Since GotToBTru picked the first prime ≥ S/2, it will be maximal with length S, and will guarantee that's there are at most 2 numbers from each period (ie, Xn+1 may not have wrapped around S, but Xn+2 definitely will have).
Re^3: Check randomly generated numbers have not been used before
by GotToBTru (Prior) on Sep 16, 2016 at 20:29 UTC

    You're exactly right about this. I knew this sort of thing had an official title, just didn't know what it was. I've seen this sort of algorithm called a "random number generator", but it is nearly the opposite. Having once issued a value in the space, there is 0% chance it will re-issue it. Well, until you start through the list a second time, in which case it will issue the very same list of numbers in exactly the same order. The "random" function in the BASIC interpreter I used 40+ years ago used something very much like this, and my first attempts at computer games were very disappointing until I figured that out ;)

    But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

      I've seen this sort of algorithm called a "random number generator", but it is nearly the opposite.

      That's the "pseudo" in "Pseudo-Random Number Generator." :)


      Give a man a fish:  <%-{-{-{-<