The Python Game Book

code games. learn Python.

User Tools

Site Tools




Theory of probability

Theory of probability is a fascinating topic by itself and get becomes even more fascinating if you apply it to games.

Recommended reading:

To apply it to games with python, you need to import python's random module (shipped with python). To simulate the throw of a six-sided dice, write:

>>>import random
>>>result = random.randint(1,6) # lower bond, upper bond
>>>print result

You can find out all functions of the random module by typing at the python prompt:

>>>import random

Some useful functions tend to use frequently are:

  • random.randint(a, b) creates a random integer between (including) a and b
  • radnom.random() creates a float between 0 and 1
  • random.choice(list) randomly choose one element of a list
en/glossary/p/probability.txt · Last modified: 2020/06/03 06:58 by horst