On 2017-05-17, at 12:59, Martin Ward wrote: > On 16/05/17 23:46, Richard Kuebbing wrote: >> Fantastic. This looks to be the level of brilliance I was looking >> for - simplicity plus 100% solution. > > To generate a random permutation of the numbers from 1 to 99,999 > the usual method is the Fisher-Yates shuffle, dating from 1938: > > https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle > Damn! So Melvyn and I won't be able to publish our re-discovery.
> This takes O(n) time, as opposed to O(n log n) for Peter's > "generate and sort" method. With only 99,999 numbers the extra CPU time > may not be significant, depending on how often you need to generate > a sequence. > Presuming that the table fits in main memory. On the first mainframes I used, 99,999 wouldn't have fit. > There are various statistical tests for randomness, if you don't > entirely trust your random number generator: > > https://en.wikipedia.org/wiki/Randomness_tests > And, even worse: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Pseudorandom_generators ... a shuffle driven by such a generator cannot possibly produce more distinct permutations than the generator has distinct possible states. ..., to minimize bias, the number of states of the PRNG should exceed the number of permutations by at least several orders of magnitude. I doubt that any PRNG available nowadays has 99999 ! internal states. (Probably no one will notice.) Is DFSORT the Swiss Army Knife of z/OS? -- gil
