Guest User

script

a guest
Jul 15th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. import math
  2. import random
  3.  
  4. rolls=2
  5. num=1000000
  6. low = 740
  7. high = 5180
  8.  
  9.  
  10. def rollingDie():
  11.     total = 0
  12.     for i in range(num):
  13.         trials = []
  14.         for j in range(rolls):
  15.             trials.append(random.randint(low, high)) # adds a trial to the array
  16.         trials.sort(reverse=True) # sorts from greatest to least
  17.         total+=trials[0]/num # adds on the greatest roll. /num for averaging
  18.     return total
  19.  
  20. def avgDist():
  21.     tot=0
  22.     for i in range(num):
  23.         tot+=abs(random.randint(low, high)- random.randint(low, high))/num
  24.     return tot
  25.  
  26. print(rollingDie())
Advertisement
Add Comment
Please, Sign In to add comment