Advertisement
Guest User

Gacha Expected Pulls Monte Carlo

a guest
Feb 25th, 2025
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. import random
  2. import math
  3.  
  4. def pulluntil(target, prob, pity):
  5.     hits = 0
  6.     count = 0
  7.    
  8.     while(hits<target):
  9.         count +=1
  10.         if (random.random() < prob):
  11.             hits += 1
  12.         if ((count%(pity))==0):
  13.             hits += 1
  14.            
  15.     return count
  16.    
  17. def getquarts(arr):
  18.     quarts = []
  19.     sarr = sorted(arr)
  20.    
  21.     quarts.append(sarr[0])
  22.    
  23.     for i in range(4):
  24.         #print(round(len(sarr)/4*(i+1)))
  25.         quarts.append(sarr[round(len(sarr)/4*(i+1))-1])
  26.        
  27.     return quarts
  28.    
  29.  
  30. def main(hits, prob, pity):
  31.     numsims = 10000
  32.    
  33.     results = []
  34.    
  35.     for i in range(numsims):
  36.         results.append(pulluntil(hits, prob, pity))
  37.        
  38. #   print(results)
  39.    
  40.     avg = 0
  41.     for i in range(len(results)):
  42.         avg += results[i]
  43.     avg /= len(results)
  44.    
  45.     q=getquarts(results)
  46.    
  47.     print(hits, " | ", round(avg,1), " | ", q[0], " | ", q[1], " | ", q[2], " | ", q[3], " | ", q[4])
  48.    
  49. print("Dupes | Mean | Trial Min | Quartile 1 | Median | Quartile 3 | Trial Max")
  50. print(":--: | :--: | :--: | :--: | :--: | :--: | :--:")
  51. for i in range(1,11):
  52.     main(i, 0.007, 200)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement