Python Random vs. Cython C Rand for Dice Rolls

Chris Angelico rosuav at gmail.com
Sun Jun 7 14:53:24 EDT 2015


On Mon, Jun 8, 2015 at 4:40 AM, C.D. Reimer <chris at 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



More information about the Python-list mailing list