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

2015-06-08 Thread Sturla Molden
On 08/06/15 19:33, Laura Creighton wrote: Better C random number generator. http://www.pcg-random.org/download.html Or for something less minimalistic, just grab randomkit.c and randomkit.h from NumPy, which implements the same Mersenne Twister as Python. That is what I usually do to get fas

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

2015-06-08 Thread Laura Creighton
Better C random number generator. http://www.pcg-random.org/download.html Laura -- https://mail.python.org/mailman/listinfo/python-list

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

2015-06-08 Thread Jeremy Sanders
C.D. Reimer wrote: > Is there something in the Cython code that I need to change and/or find > a better C random number generator? This may not be helpful, but numpy is pretty helpful for this sort of thing: import numpy import numpy.random a=numpy.random.randint(1,6,5000) b=numpy.random.ra

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

2015-06-07 Thread Cecil Westerhof
On Sunday 7 Jun 2015 19:23 CEST, Chris Angelico wrote: > On Mon, Jun 8, 2015 at 3:17 AM, C.D. Reimer wrote: >> This is the Python script that takes ~197 seconds to complete. >> >> import random, time >> >> startTime = time.time() >> >> f = [0] * 12 >> >> for i in range(5000): >> >> a = rando

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

2015-06-07 Thread C.D. Reimer
On 6/7/2015 11:33 AM, Steven D'Aprano wrote: C rand is not even close to random. The technical term for it is "shite". Looking through the BASIC book, I remembered all the tricks needed to get a half-way decent number generator on a 1MHz processor back in the day. Either the numbers start rep

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

2015-06-07 Thread Chris Angelico
On Mon, Jun 8, 2015 at 4:40 AM, C.D. Reimer wrote: > PS Z:\projects\programming\python\basic_games\fastdice> python > test_fastdice.py > > TOTAL SPOTS NUMBER OF TIMES > > 21389911 > > 3222 > > 44168248 > > 55553632 > > 6

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

2015-06-07 Thread C.D. Reimer
On 6/7/2015 10:33 AM, Chris Angelico wrote: 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 goin

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

2015-06-07 Thread Steven D'Aprano
On Mon, 8 Jun 2015 03:17 am, C.D. Reimer wrote: > Greetings, > > I've revisited my misbegotten childhood by translating the programs from > "BASIC Computer Games" by David H. Ahl into Python. This is mostly an > exercise in unraveling spaghetti code with all those GOTO statements > going all over

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

2015-06-07 Thread Chris Angelico
On Mon, Jun 8, 2015 at 3:59 AM, C.D. Reimer wrote: > On 6/7/2015 10:23 AM, Chris Angelico wrote: >> >> Before you go any further, can you just try this script, please, and >> see how long it takes to run? >> >> import random, time >> startTime = time.time() >> for i in range(5000): >> pas

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

2015-06-07 Thread C.D. Reimer
On 6/7/2015 10:23 AM, Chris Angelico wrote: Before you go any further, can you just try this script, please, and see how long it takes to run? import random, time startTime = time.time() for i in range(5000): pass print '\n', time.time() - startTime I know, seems a stupid thing to try,

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

2015-06-07 Thread Chris Angelico
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 numbe

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

2015-06-07 Thread Chris Angelico
On Mon, Jun 8, 2015 at 3:17 AM, C.D. Reimer wrote: > This is the Python script that takes ~197 seconds to complete. > > import random, time > > startTime = time.time() > > f = [0] * 12 > > for i in range(5000): > > a = random.randint(1,6) > > b = random.randint(1,6) > > f[(a + b) -