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


Groups > comp.lang.python > #19952

Re: difference between random module in python 2.6 and 3.2?

From Serhiy Storchaka <storchaka@gmail.com>
Subject Re: difference between random module in python 2.6 and 3.2?
Date 2012-02-07 12:05 +0200
References (6 earlier) <jgo3pp$269s$1@ns.felk.cvut.cz> <jgo4fg$26h9$1@ns.felk.cvut.cz> <4F302088.8010901@gmail.com> <mailman.5483.1328556387.27778.python-list@python.org> <jgpimq$2ndb$2@ns.felk.cvut.cz>
Newsgroups comp.lang.python
Message-ID <mailman.5495.1328609155.27778.python-list@python.org> (permalink)

Show all headers | View raw


07.02.12 00:06, Matej Cepl написав(ла):
> return seq[int(random.random() * len(seq))]
> 
> doesn't seem like something so terrible (and maintenance intense). :)

_choice('abc') returns 'a' with probability P('a') = 1501199875790165/4503599627370496 = 1/3 - 1/13510798882111488 and 'b' with probability P('b') = 3002399751580331/9007199254740992 = 1/3 + 1/27021597764222976. P('b') - P('a') = 1/9007199254740992.

This may be acceptable for your application, but for applications that are concerned not only about the repeatability of results, but the accuracy and consistency with the results obtained by other (not Python) applications, it is better to get rid of such a notorious bias.

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


Thread

difference between random module in python 2.6 and 3.2? Matej Cepl <mcepl@redhat.com> - 2012-02-06 02:27 +0100
  Re: difference between random module in python 2.6 and 3.2? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-06 04:01 +0000
    Re: difference between random module in python 2.6 and 3.2? Terry Reedy <tjreedy@udel.edu> - 2012-02-06 00:07 -0500
      Re: difference between random module in python 2.6 and 3.2? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-06 05:56 +0000
        Re: difference between random module in python 2.6 and 3.2? Terry Reedy <tjreedy@udel.edu> - 2012-02-06 02:27 -0500
          Re: difference between random module in python 2.6 and 3.2? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-06 08:05 +0000
            Re: difference between random module in python 2.6 and 3.2? Matej Cepl <mcepl@redhat.com> - 2012-02-06 09:45 +0100
              Re: difference between random module in python 2.6 and 3.2? Matej Cepl <mcepl@redhat.com> - 2012-02-06 09:57 +0100
                Re: difference between random module in python 2.6 and 3.2? Tim Chase <python.list@tim.thechases.com> - 2012-02-06 13:26 -0600
                Re: difference between random module in python 2.6 and 3.2? Matej Cepl <mcepl@redhat.com> - 2012-02-06 23:06 +0100
                Re: difference between random module in python 2.6 and 3.2? Serhiy Storchaka <storchaka@gmail.com> - 2012-02-07 12:05 +0200
              Re: difference between random module in python 2.6 and 3.2? Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-02-07 16:11 +0100
            Re: difference between random module in python 2.6 and 3.2? Mel Wilson <mwilson@the-wire.com> - 2012-02-06 10:20 -0500

csiph-web