Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #54939

Re: card dealer

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.062
X-Spam-Evidence '*H*': 0.88; '*S*': 0.00; 'algorithm': 0.04; 'remaining': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'random': 0.14; 'correlation': 0.16; 'disaster.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'simple)': 0.16; 'struck': 0.16; 'wrote:': 0.18; '(where': 0.19; "python's": 0.19; 'select': 0.22; 'header:User-Agent:1': 0.23; 'fairly': 0.24; "i've": 0.25; 'this:': 0.26; '(for': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'idea': 0.28; 'rest': 0.29; 'generally': 0.29; 'properties': 0.29; '(which': 0.31; 'checking': 0.33; 'could': 0.34; 'problem': 0.35; 'problem.': 0.35; 'but': 0.35; 'there': 0.35; 'limitations': 0.36; 'object,': 0.36; 'sequence': 0.36; 'next': 0.36; 'charset:us- ascii': 0.36; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'even': 0.60; 'analyze': 0.60; 'helps': 0.61; 'no.': 0.61; 'numbers': 0.61; 'entire': 0.61; 'skip:* 10': 0.61; "you're": 0.61; 'first': 0.61; 'complete': 0.62; "you've": 0.63; 'kind': 0.63; 'such': 0.63; 'card': 0.63; 'become': 0.64; 'cards': 0.65; 'between': 0.67; 'close': 0.67; 'default': 0.69; 'batchelder': 0.84; 'cards,': 0.84; 'dealt': 0.91; 'subject:card': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dave Angel <davea@davea.name>
Subject Re: card dealer
Date Sat, 28 Sep 2013 12:56:15 +0000 (UTC)
References <0617088e-5aa3-4c5d-b660-22040ee858a1@googlegroups.com> <l23q0r$u27$1@ger.gmane.org> <mailman.380.1380283737.18130.python-list@python.org> <l24am7$j2k$2@dont-email.me> <mailman.394.1380318056.18130.python-list@python.org> <524670be$0$30000$c3e8da3$5496439d@news.astraweb.com> <5246AFFD.9090401@nedbatchelder.com>
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 174.32.174.35
User-Agent XPN/1.2.6 (Street Spirit ; Linux)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.410.1380373000.18130.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1380373000 news.xs4all.nl 15967 [2001:888:2000:d::a6]:57699
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:54939

Show key headers only | View raw


On 28/9/2013 06:31, Ned Batchelder wrote:

    <snip>
>
> I've thought that way about it too: there are so many shuffles any way, 
> it won't be a problem.  But think about it like this:  if you shuffle a 
> deck of 52 cards with a default Python random object, then once you have 
> dealt out only 28 cards, the entire rest of the deck is completely 
> determined.  That is, given the sequence of the first 28 cards, there's 
> only one choice for how the remaining 24 will be dealt.  Depending on 
> what you need from your deck of cards, that could be a complete disaster.
>
> Is it a problem for a card game simulation?  No.  Is it a problem for a 
> program that analyze correlations between the start of the deck and the 
> end of the deck?  Maybe.
>

Only if there is some correlation between the random number algorithm
and whatever properties you're checking between start and end of deck. 
And if there is, then you've just struck one of the limitations of a
*pseudo* random gen.

I have no idea what sheme is actually used in Python's generator, but
one approach that helps avoid such troubles is to keep a pool of the
"next" P random numbers (where P might be a few hundred).  Then use an
*independent* random number generator (which could be very simple) to
select which item of the pool to use next (followed by replacement from
the first).

it's kind of a local-shuffle of the very long stream of numbers.

Even fairly poor random number generators, if they generate close to
2**n values (for a int size of n) generally become very good when
shuffled this way.


-- 
DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

card dealer markotaht@gmail.com - 2013-09-27 03:24 -0700
  Re: card dealer Dave Angel <davea@davea.name> - 2013-09-27 11:26 +0000
  Re: card dealer MRAB <python@mrabarnett.plus.com> - 2013-09-27 12:27 +0100
  Re: card dealer Alister <alister.ware@ntlworld.com> - 2013-09-27 11:41 +0000
  Re: card dealer Dave Angel <davea@davea.name> - 2013-09-27 12:08 +0000
    Re: card dealer Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-27 16:10 +0000
      Re: card dealer Dave Angel <davea@davea.name> - 2013-09-27 21:00 +0000
      Re: card dealer Ned Batchelder <ned@nedbatchelder.com> - 2013-09-27 17:40 -0400
        Re: card dealer Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-28 06:01 +0000
          Re: card dealer Ned Batchelder <ned@nedbatchelder.com> - 2013-09-28 06:31 -0400
          Re: card dealer Dave Angel <davea@davea.name> - 2013-09-28 12:56 +0000
          Re: card dealer Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-28 16:49 +0200
            Re: card dealer Tim Roberts <timr@probo.com> - 2013-09-28 17:04 -0700

csiph-web