vendredi 10 décembre 2021

I'm trying to 'draw' curve of random distribution(Galton board) but it 'avoids' certain positions

I want to simulate behavior of the Galton board getting a dictionary with position in key and frequency in value.

import random

board = {-5:0, -4:0, -3:0, -2:0, -1:0, 0:0, 1:0, 2:0, 3:0, 4:0, 5:0}

for i in range(200):
  num = 0
  for x in range(5):
    num+= random.choice([-1,1])
  d[num]+=1

And then I get something like this: {-5:7, -4:0, -3:35, -2:0, -1:60, 0:0, 1:58, 2:0, 3:29, 4:0, 5:11}

Also when number of positions from 0 to an end is even, the script gives more positions filled but the second and penult ones always remain epmty. Why is it so and how can I get proper realization of the idea?




Aucun commentaire:

Enregistrer un commentaire