Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente | Prochaine révisionLes deux révisions suivantes | ||
teaching:exos:simulations_random_walks_codes [2013/11/14 09:56] – villersd | teaching:exos:simulations_random_walks_codes [2018/11/05 11:35] – [Génération de nombres aléatoires] villersd | ||
---|---|---|---|
Ligne 5: | Ligne 5: | ||
===== Génération de nombres aléatoires ===== | ===== Génération de nombres aléatoires ===== | ||
- | <sxh python; title : 01_random.py> | + | <code python 01_random.py> |
- | #!/usr/bin/env python | + | # |
# -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||
+ | """ | ||
+ | cf. documentation cf http:// | ||
+ | random number generation - génération de nombres aléatoires | ||
+ | functions of interest : choice, randint, seed | ||
+ | """ | ||
from random import * | from random import * | ||
- | # cf. documentation cf http:// | ||
- | # random number generation - génération de nombres aléatoires | ||
- | # functions of interest : choice, randint, seed | ||
- | facepiece=[' | + | facepiece = [' |
- | valeurpiece=[0.01, | + | valeurpiece = [0.01, |
- | #for i in range(1): | + | for i in range(1): |
# choice : random choice of an element from a list | # choice : random choice of an element from a list | ||
- | | + | print(choice(facepiece), |
# randint : return a random integer number between 2 values (including limits) | # randint : return a random integer number between 2 values (including limits) | ||
- | | + | print(randint(0, |
- | | + | print(choice(range(0, |
+ | | ||
# seed(ANY_DATA) : seeding of the random number generator with any (constant) data | # seed(ANY_DATA) : seeding of the random number generator with any (constant) data | ||
Ligne 32: | Ligne 35: | ||
seed() | seed() | ||
for i in range(10): | for i in range(10): | ||
- | print randint(1000, | + | print(randint(1000, |
- | print " " | + | print(" ") |
- | </sxh> | + | </code> |
===== Histogrammes de nombres aléatoires | ===== Histogrammes de nombres aléatoires |