Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1a.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'memory.': 0.05; 'sys': 0.05; '#include': 0.07; '(especially': 0.07; 'main()': 0.07; '++i)': 0.09; 'modulo': 0.09; 'toss': 0.09; 'cc:addr:python-list': 0.10; 'python': 0.11; 'weird': 0.15; '"int': 0.16; 'as-is': 0.16; 'correctness.': 0.16; 'declaration': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'middle,': 0.16; 'peak': 0.16; 'subject:Cython': 0.16; 'worst': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.21; 'cc:addr:python.org': 0.21; 'produces': 0.22; 'void': 0.22; 'am,': 0.23; '2015': 0.23; 'replacing': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'not.': 0.27; 'raw': 0.27; 'least': 0.27; 'message- id:@mail.gmail.com': 0.28; "i'm": 0.29; 'curve': 0.29; 'initialized': 0.29; 'loop,': 0.29; 'random': 0.29; "i'd": 0.31; 'similar': 0.32; 'int': 0.33; 'case,': 0.34; 'add': 0.34; 'received:google.com': 0.34; 'done': 0.35; 'but': 0.36; 'text': 0.36; 'there': 0.36; 'basic': 0.36; 'subject:: ': 0.37; "won't": 0.38; 'systems,': 0.38; 'enough': 0.39; 'some': 0.40; 'your': 0.60; 'real': 0.61; 'here.': 0.61; 'skip:u 10': 0.62; 'high': 0.62; 'more': 0.62; 'day.': 0.63; 'results': 0.66; 'subject:. ': 0.66; 'low': 0.83; 'chrisa': 0.84; 'reminds': 0.84; 'to:none': 0.90; 'indicator': 0.91; 'yours.': 0.93 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=Vs6DkAyOlPzULErkh3YUWWN1nH23cIjf0g7X4Wcx81Q=; b=JuOJK8Q3uHTYHd4WDe8/+ppK/bXWRAgdruQG9JY0YdI2yex/POGMaponxqt+DU1bEG 7k8dsTF9i8f4KYxt8stPO1JD/342MTx2fCJZndyRbh7XlBKZSO3DNfRZDx5aau6n1Xaw q+i3d4Q0aAINF5z8e+Swhyf8pBWU9Lc7Ea8vESCzOjemVQF00JrUKjDr6d6s6lxI4Xwq oWhxt79CYBliGRK2yNqzdVyNzNIBbBAyjNGjGviqAl25cEZFFbUM0hudLr3SLPBbozt8 rhCoD6XBxY/rjFrc3pgoe+Wi1CWL15OyX94lU04/9i8LMzYblS59lXsfMvW/Yh3GQQFw 3oEw== MIME-Version: 1.0 X-Received: by 10.107.131.196 with SMTP id n65mr15574288ioi.53.1433698380372; Sun, 07 Jun 2015 10:33:00 -0700 (PDT) In-Reply-To: <55747C96.7090006@cdreimer.com> References: <55747C96.7090006@cdreimer.com> Date: Mon, 8 Jun 2015 03:33:00 +1000 Subject: Re: Python Random vs. Cython C Rand for Dice Rolls From: Chris Angelico Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 83 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1433698383 news.xs4all.nl 2922 [2001:888:2000:d::a6]:46264 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:92278 On Mon, Jun 8, 2015 at 3:17 AM, C.D. Reimer wrote: > The Python random shows a uniform bell curve with low numbers at the ends > and the peak in the middle, which is similar to the text in the book for the > BASIC program. The Cython C rand is over all the place (especially with a > negative number), which reminds me how bad the random number generator was > on my 1MHz C64 in the day. The negative result is a strong indicator that you're not seeing the results of rand() here. While there is a potential for bias (check out RAND_MAX, and consider that there may be some small bias there; although on most modern systems, RAND_MAX is going to be high enough that the bias from modulo 6 won't be highly visible), it's much MUCH more likely that you're looking at uninitialized memory. I'm not overly familiar with Cython, but can you simply add "={0}" to the declaration to force it to be initialized to all zeroes? That's what I'd do in raw C. Here's the same thing done in straight-forward C: #include #include void roll(int *f,int x) { int i, a, b; for (i=0; i