Python Random vs. Cython C Rand for Dice Rolls
Jeremy Sanders
jeremy at jeremysanders.net
Mon Jun 8 03:43:33 EDT 2015
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,50000000)
b=numpy.random.randint(1,6,50000000)
numpy.bincount(a+b-1)
array([ 0, 1999229, 4000369, 5999372, 7999232, 9998769, 8003430,
5998538, 4001160, 1999901])
This takes a few seconds on my system.
Jeremy
More information about the Python-list
mailing list