Advertisement
Programmin-in-Python

Sample Space of Tossing n Dice

Dec 19th, 2020 (edited)
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. from random import shuffle
  2.  
  3. def dicetoss(n):
  4.     sides = [str(i) for i in range(1,7)]
  5.     SampleS = [i*n for i in sides] 
  6.  
  7.     if n == 1:
  8.         print(SampleS)
  9.  
  10.     else:
  11.         L1 = []
  12.  
  13.         for i in sides:
  14.             for j in range(n):
  15.                 L1.append(i)
  16.  
  17.         while True:
  18.             shuffle(L1)
  19.  
  20.             event = L1[:n]
  21.             str1 = ""
  22.  
  23.             for i in event:
  24.                 str1 += i
  25.             else:
  26.                 if str1 not in SampleS:
  27.                     SampleS.append(str1)
  28.                     str1 = ''
  29.  
  30.                 else:
  31.                     continue           
  32.  
  33.             if len(SampleS) == 6**n:
  34.                 break
  35.  
  36.         SampleS.sort()
  37.  
  38.         for i in range(1,7):
  39.             for j in SampleS:
  40.                 if str(i) == j[0]:
  41.                     print(j, end=", ")
  42.             else:
  43.                 print()
  44.  
  45. dicetoss(3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement