laziness, impatience, and hubris PerlMonks

### Re: Shuffling CODONS

 on Jun 07, 2018 at 18:32 UTC ( #1216128=note: print w/replies, xml ) Need Help??

Hello there. I realize this may be just a learning exercise, but the mention of a 'proper' shuffle came up above...

A shuffle is a random list permutation, of which there are n! possibilities. A 'proper' shuffle would emphasize the quality of the random source. PRNG needs at least log2(n!) bits of internal state to be able to generate all possible permutations. List::Util shuffle is likely using drand48.

```\$ perl -MList::Util=sum -e 'print 1/log(2) * sum map log, 1..17;'
48.337603311133
\$ perl -MList::Util=sum -e 'print 1/log(2) * sum map log, 1..1000;'
8529.39800420478
```

As you can see, 48 bits is not enough to properly shuffle a list of 17 elements. For one thousand element shuffle, more than a kilobyte of randomness is required.

Replies are listed 'Best First'.
Re^2: Shuffling CODONS
by BrowserUk (Pope) on Jun 07, 2018 at 19:07 UTC
As you can see, 48 bits is not enough to properly shuffle a list of 17 elements. For one thousand element shuffle, more than a kilobyte of randomness is required.

Utter twaddle! What I see is someone adding 2 + 1/log2 * sum of the log2 of an arbitrary list and drawing a random, and wrong, conclusion.

The Knuth-Fisher-Yates shuffle only needs to be able to pick 1 from N -- that is, generate a uniform random number between 1 and N; where N is the number of elements in the array -- as proven by Donald Knuth, arguably the greatest Computer Scientist of the current era.

Discuss.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

"arguably the greatest Computer Scientist of the current era. "

But they were not called the "Donald of Computer Programming", he looked up to someone else

"One of the first times I was ever asked about the title of my books was in 1966, during the last previous ACM national meeting held in Southern California. This was before any of the books were published, and I recall having lunch with a friend at the convention hotel. He knew how conceited I was, already at that time, so he asked if I was going to call my books "An Introduction to Don Knuth." I replied that, on the contrary, I was naming the books after him. His name: Art Evans. (The Art of Computer Programming, in person.) "
http://www.paulgraham.com/knuth.html
https://cacm.acm.org/magazines/1974/12/11626-computer-programming-as-an-art/abstract

"Always Mount a Scratch Monkey" https://www.acme.com/jef/netgems/scratch_monkey.html

... uniform random number between 1 and N; where N is the number of elements in the array ...
Correction: several such random numbers. Alternatively, one random number 1..N, where N is the number of permutations.

The shuffle algorithm needs a random number sequence of finite length. A PRNG with 48 bits of internal state can generate at most 248 different sequences (of some particular length), because it is deterministic. If there are more permutations than that, some will never be selected.

Those using GNU/Linux can take a quick glimpse at the working of the standard shuffle tool, shuf.

```\$ strace -s0 -e open,read shuf -o /dev/null -i 1-17
...
open("/dev/urandom", O_RDONLY)          = 3
...
\$ strace -s0 -e open,read shuf -o /dev/null -i 1-1000
...
open("/dev/urandom", O_RDONLY)          = 3
...
```
Here, in order to shuffle a list of integers 1-17, shuf actually wants 11 random bytes. For 1000 elements, shuf reads 1250 bytes of /dev/urandom.

Correction: several such random numbers. Alternatively, one random number 1..N, where N is the number of permutations.

Still garbage!

A PRNG with 48 bits of internal state can generate at most 248 different sequences

You really believe that? Then tell me, how is it that the 32-bit Mersenne Twister has a period of 219937 − 1?

You really don't have a clue do you. No wonder you hide in anonymity.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

Create A New User
Node Status?
node history
Node Type: note [id://1216128]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2018-12-13 03:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How many stories does it take before you've heard them all?

Results (61 votes). Check out past polls.

Notices?