Translations of this page:
Table of Contents
Theory of probability
Theory of probability is a fascinating topic by itself and get becomes even more fascinating if you apply it to games.
To apply it to games with python, you need to import python's random module (witch is shipped with python).
To simulate the throw of a six-sided dice, write:
- dice.py
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
>>>help("random")
Some functions i tend to use frequently are:
random.randint(a, b)creates a random integer between (including) a and bradnom.random()creates a float between 0 and 1random.choice(list)randomly choose one element of a list
overview
external links
- Wikipedia: http://en.wikipedia.org/wiki/Probability
- Python.org documentation (2.x) for random module: http://docs.python.org/library/random.html
- Python.org documentation (3.x) for random module: http://docs.python.org/py3k/library/random.html








