teaching:exos:simulations_random_walks_codes

Ceci est une ancienne révision du document !


Simulations numériques de marches aléatoires : programmes en Python

<sxh python; title : 01_Random.py> #!/usr/bin/env python #!/usr/bin/python

from random import * # cf. documentation cf http://docs.python.org/library/random.html # random number generation - génération de nombres aléatoires # functions of interest : choice, randint, seed

facepiece=['pile','face'] valeurpiece=[0.01,0.02,0.05,0.1,0.2,0.5,1.,2.]

#for i in range(1):

  # choice : random choice of an element from a list
  #print choice(facepiece), choice(valeurpiece)
  # randint : return a random integer number between 2 values (including limits)
  #print randint(0,10)       # imprime un nombre aléatoire entre 0 et 10
  #print choice(range(0,11,1))  # same function, using choice and range to create the list
  

# seed(ANY_DATA) : seeding of the random number generator with any (constant) data # in order to generate reproducible random sequences. # seed() - without data - uses internal clock value to “randomly” initiate the generator !

for j in range(3):

  #seed('ma chaîne personnielle')  # reproducible initialization
  seed()   # to randomly initiate the generator
  for i in range(10):
      print randint(1000,9999)
  print " "

</sxh>

Ce site web utilise des cookies. En utilisant le site Web, vous acceptez le stockage de cookies sur votre ordinateur. Vous reconnaissez également que vous avez lu et compris notre politique de confidentialité. Si vous n'êtes pas d'accord, quittez le site.En savoir plus
  • teaching/exos/simulations_random_walks_codes.1384356928.txt.gz
  • Dernière modification : 2013/11/13 16:35
  • de villersd