Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.102 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.80; '*S*': 0.01; 'importing': 0.05; 'plenty': 0.07; '128': 0.09; 'bits': 0.09; 'random': 0.14; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'variable': 0.18; "python's": 0.19; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'fairly': 0.24; 'initial': 0.24; "i've": 0.25; 'holds': 0.26; 'order.': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'function': 0.29; 'array': 0.29; '(unless': 0.31; 'sep': 0.31; 'front': 0.32; 'fri,': 0.33; 'period': 0.33; 'could': 0.34; 'possible.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'handle': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'enough': 0.39; 'how': 0.40; 'dave': 0.60; 'ago,': 0.61; 'took': 0.61; 'times': 0.62; 'card': 0.63; 'more': 0.64; 'granted': 0.65; 'yourself': 0.78; 'seeds': 0.84; 'angel': 0.91; 'have.': 0.93; 'subject:card': 0.93; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=2+ZLfxZpelGwx4jWQg4SSvjV0oT+nu7SMFxg6PmfXiQ=; b=hPb0jRMyc/uhm1tWCZqZ9Us6EgaNzrCK2u8WukPrba/1IlNOtb9BMhe/xVTyxCUIQv 6Zyrc2aSC/roRan2EBlhrsbOw6svKqoDZ61bZM2RxUPs6UGmU0BJ8TCnvRrc5VIotFkz AvfRFBhUYXkVJR2uvidwUdpIH5Atk1FZaLNfROrHPtb2EiSs8ezpTFteX/8pt0VoZcRJ 1k7Y54OK8+1JzQbg2uv93f5zzaqvlYRKjvq0KA7mtfXxyWCKhXfzMLgFmxg59V2FNnqp 9PR5aSonDDc2FBpWO8pwlRKf1UlyKiUf/nijp5VuFSF+2HSKFPyOYUbf4acuzyu5ijkR RErA== X-Received: by 10.49.71.106 with SMTP id t10mr12140034qeu.26.1380318047776; Fri, 27 Sep 2013 14:40:47 -0700 (PDT) Sender: Ned Batchelder Date: Fri, 27 Sep 2013 17:40:46 -0400 From: Ned Batchelder User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: python-list@python.org Subject: Re: card dealer References: <0617088e-5aa3-4c5d-b660-22040ee858a1@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1380318056 news.xs4all.nl 15870 [2001:888:2000:d::a6]:45815 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54913 On 9/27/13 12:10 PM, Denis McMahon wrote: > On Fri, 27 Sep 2013 12:08:33 +0000, Dave Angel wrote: > >> i recall >> writing a shuffle function in C decades ago, which took an array of (52) >> unique items and put them in random order. > Whenever I tried to write shuffles I came up against a fairly fundamental > limit: > > 52! > prng states > > Granted prngs seem to be better on the importing entropy from elsewhere > front these days. > Python's PRNG holds plenty of state to handle card shuffling. Python's random number generator has a period of 2**19337-1, so it has that many states. That is much larger than 52!, about 10**5933 times larger. (Unless I've botched the math...) The other variable is how many states the initial seed can have. If os.urandom is available, then it seeds with 16 bytes of OS-supplied randomness. But 52! is about 2**226, so the 128 bits of seed isn't enough to make all shuffles possible. You could seed a Random yourself with more bits if you really wanted to. --Ned.