Does shuffle() produce uniform result ?

Steve Holden steve at
Fri Aug 24 13:42:12 CEST 2007

tooru honda wrote:
> Hi,
> I have read the source code of the built-in random module,  
> After also reading Wiki article on Knuth Shuffle algorithm, I wonder if 
> the shuffle method implemented in produces results with modulo 
> bias.
> The reasoning is as follows: Because the method random() only produces 
> finitely many possible results, we get modulo bias when the number of 
> possible results is not divisible by the size of the shuffled list.
> 1. Does shuffle() produce uniform result ?
Given the cycle length of the Mersenne twister algorithm that generates 
the underlying random numbers, it would have to be a pretty long list to 
see a significant bias, don't you think? Have you done any calculations 
on the length of list you propose to use?

> 2. If not, is there a fast and uniform shuffle() available somewhere ?
Frankly I don't think you need to worry.

Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd 
Skype: holdenweb
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

More information about the Python-list mailing list