On Mar 15, 4:41 pm, Kevin <kevinloran...@gmail.com> wrote:
> ...me make a graph for this code.
> The code makes a distribution of 2 dice.
>
> It would be nice to have a graph to go with it.
>
> from random import random
> maximum = 10000
> counts = [0,0,0,0,0,0,0,0,0,0,0,0,0,0]
> n = 0
> while n < maximum:
>     dieOne = int(random()*6)+1
>     dieTwo = int(random()*6)+1
>     dieSum = dieOne + dieTwo
>     counts [dieSum] = counts [dieSum] + 1
>     n = n + 1
> counts [1:]

Another way of doing that is
(see 
http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.random_integers.html
)

from numpy.random import random_integers
dsums = random_integers(1, 6, 10000) + random_integers(1, 6, 10000)
from matplotlib import pyplot
counts = pyplot.hist(dsums, 11)[0]; counts

array([ 279,  569,  845, 1072, 1398, 1683, 1355, 1106,  842,  576,
275])

pyplot.savefig("sage1.png")

Alec Mihailovs

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to