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


Groups > comp.lang.python > #92290

Re: Python Random vs. Cython C Rand for Dice Rolls

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.023
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'subject:Python': 0.05; 'cc:addr:python-list': 0.10; 'python': 0.11; 'declaration,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:Cython': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.21; 'cc:addr:python.org': 0.21; 'space.': 0.22; 'am,': 0.23; '2015': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'message- id:@mail.gmail.com': 0.28; 'initialized': 0.29; 'array': 0.29; 'function': 0.30; 'values': 0.30; 'certainly': 0.31; 'values.': 0.33; 'definition': 0.34; 'received:google.com': 0.34; "isn't": 0.35; 'but': 0.36; 'responsible': 0.37; 'subject:: ': 0.37; 'where': 0.40; 'times': 0.61; 'total': 0.64; 'subject:. ': 0.66; 'chrisa': 0.84; 'to:none': 0.90
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=Xel+U4JRXm+9qU9SsSJYtVYt05VeIirakBa5nqjU6bo=; b=sA+l5rr7n5IBRAQpO5LaqDSJb33wDikr9LuXx4wIEPR7WCrtKOqoZlhLjZ+nsQSC63 kofHNDUBwgBsFrm0j0y8RWFzyfp9OM+xh4ur2v62K5ro+fWyslY+Jzs9P6y57Wl5/UIa ltYhwBIvOZYWjLZJOINzQOQoblEjbXqlJ59O7w5Czke0EYjnT9gLGZeUFmmFtYA44Pcc U/1cg66e7tiaQH/al5cmLNheegj1icdDXt6+Wg5I4DRB+GDSATdNmFLhNTQyIiPe3xlZ Ak3v0gn9O9VHGuBdgU8o4Ilu1xGSRrlgOYHP3bqucRv+Xghj7VojOsbnpQMzGAk4MiYm eSIw==
MIME-Version 1.0
X-Received by 10.50.2.3 with SMTP id 3mr9333360igq.34.1433703205059; Sun, 07 Jun 2015 11:53:25 -0700 (PDT)
In-Reply-To <55749025.8090501@cdreimer.com>
References <55747C96.7090006@cdreimer.com> <CAPTjJmo0Aw961q54BySZBSDdD8xqCPFjMezcytzWxrE0m6afTw@mail.gmail.com> <55749025.8090501@cdreimer.com>
Date Mon, 8 Jun 2015 04:53:24 +1000
Subject Re: Python Random vs. Cython C Rand for Dice Rolls
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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.272.1433703214.13271.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1433703214 news.xs4all.nl 2857 [2001:888:2000:d::a6]:50950
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:92290

Show key headers only | View raw


On Mon, Jun 8, 2015 at 4:40 AM, C.D. Reimer <chris@cdreimer.com> wrote:
> PS Z:\projects\programming\python\basic_games\fastdice> python
> test_fastdice.py
>
> TOTAL SPOTS     NUMBER OF TIMES
>
>  2                1389911
>
>  3                2777722
>
>  4                4168248
>
>  5                5553632
>
>  6                6944907
>
>  7                8334670
>
>  8                6945597
>
>  9                5553557
>
>  10               4167485
>
>  11               2775806
>
>  12               1388465
>
> 1.65599989891
>
>
> I had to put the array definition outside of the function declaration, where
> it's automatically initialized to zero in the global space.

Yep, that's one valid way to force them all to zero (per C spec). And
now you're seeing reasonable values. The rand() function may not be
all that great, but it certainly isn't responsible for the bizarre
values you were seeing :)

ChrisA

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


Thread

Re: Python Random vs. Cython C Rand for Dice Rolls Chris Angelico <rosuav@gmail.com> - 2015-06-08 04:53 +1000

csiph-web