# Simulate Events (Solution)

Copied!
Happy Pythoning!

Joon

Hi, maybe it’s a bit too soon, but this exercise would be a good opportunity to introduce how random.seed works in a simple way. For example at the end of the exercise you could show the learner how to find a seed value that allows them to verify that their function `roll()` correctly returns all 6 values.

Something like:

``````for seed_nb in range(100_000):
random.seed(seed_nb)
values = [roll() for i in range(6)]
if values == [1, 2, 3, 4, 5, 6]:
print(f"{seed_nb=}")
``````

or similar.

Obviously for such a simple function like `roll()` it’s not very useful to use `random.seed()` to debug as long as you read the documentation of `random.randint()` (or remember the lesson introducing it), but the idea would just be to introduce what `random.seed()` does and how it can be useful in a simple way. Or maybe explained separately as a short single video in the lessons?

That said maybe you already introduce `random.seed()` in an equally simple way later on in the path ^^, if so, disregard that, it’s just something I thought about since you chose to introduce `random.randint()` very early.

P.S. I know that at this point of the path the lists have not been introduced yet but the same thing could be shown with 6 variables or something.

Martin Breuss RP Team

@Joon that’s a fun idea for a lesson to introduce `random.seed()` :D I’d encourage learners who read this to give it a try and post your seeds that make the dye roll in order below :)

We don’t go very deeply into using the `random` module in the Python Basics learning path, but for learners who want more, you can check out the tutorial on random number generation.

Anonymous

After looking through the random module came across the choices method, after playing around with it, decided to implement it.

``````from time import sleep
from random import choices

dice_probability = (1.05, 1.05, 1.05, 1.05, 0.95, 0.90)

def roll():
return choices(list(range(1, 7)), weights=dice_probability, k=1)[0]

print('Rolling die', end='')
for i in range(3):
print('.', end='')
sleep(1)
else:
print()

print(f'Dice has revealed itself:')
input('Press Enter to summon thee!')

dice_roll = roll()