On 12/13/2017 8:28 AM, bo...@choices.random.py wrote:
nick.martin...@aol.com (nick martinez2) writes:

def rollDie(number):
     rolls = [0] * 6
     for i in range(0, number):
         roll=int(random.randint(1,6))

One could just as well use randint(0, 5) and skip the -1 below.

         rolls[roll - 1] += 1
     return rolls

This returns a list with a count of how many times each of 1 to 6 is chosen in *number* rolls.

def rollDie(number):
     from random import choices
     return choices((1,2,3,4,5,6), k=number)

This returns a list with all *number* rolls. Assuming the the first function is the one wanted, one could feed choices into a counter. (The import should be outside of the function.)

def rollDie(number):
    rolls = [0] * 6
    for i in random.choices((0,1,2,3,4,5), k=number):
        rolls[i] += 1
    return rolls

--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to