Advertisement
Guest User

Untitled

a guest
Mar 4th, 2021
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Sub A1sim()
  4.  
  5. Dim numpull As Long
  6. Dim numsimul As Long
  7. Dim i As Long
  8. Dim j As Long
  9. Dim k As Integer
  10. Dim min As Long
  11. Dim max As Long
  12. Dim A_prob As Double
  13. Dim S_prob As Double
  14. Dim total_prob As Double
  15. Dim got_S As Integer
  16.  
  17. Dim Start As Single
  18. Dim Runtime As Single
  19. Dim ElapsedTime As String
  20.  
  21.  
  22. numsimul = InputBox("Number of simulations to run")
  23. S_prob = 1.5
  24. A_prob = 13.5
  25. total_prob = A_prob + S_prob '15
  26. got_S = 0
  27.  
  28. Start = Timer
  29.  
  30.  
  31. Range("A2:Z1000000").ClearContents
  32. numpull = 0
  33.  
  34.  
  35. Application.ScreenUpdating = False
  36. For j = 1 To numsimul
  37.     Range("A2:C1000000").ClearContents
  38.     numpull = 0
  39.     got_S = 0
  40.  
  41.     i = 1
  42.     Do While numpull = 0
  43.     Cells(i + 1, 1) = "=RAND()"
  44.     Cells(i + 1, 1).Value = Cells(i + 1, 1).Value * 100
  45.     Cells(i + 1, 2).Value = 0
  46.     'general
  47.    If Cells(i + 1, 1).Value <= total_prob Then
  48.         Cells(i + 1, 2).Value = 1
  49.     End If
  50.     If Cells(i + 1, 1).Value <= S_prob Then
  51.         Cells(i + 1, 3) = "S!"
  52.         numpull = i
  53.     End If
  54.     '10 guarantee
  55.    If i >= 10 And Cells(i + 1, 1).Value > total_prob Then
  56.         If Excel.WorksheetFunction.Sum(Range(Cells(i - 8, 2), Cells(i, 2))) = 0 Then
  57.             'here we're assuming that on the guarantee, the chances to get S rank vs A rank are proportional to listed rates
  58.            Cells(i + 1, 1) = "=RAND()"
  59.             Cells(i + 1, 1).Value = Cells(i + 1, 1).Value * 100
  60.             Cells(i + 1, 2).Value = 1
  61.             If Cells(i + 1, 1).Value <= S_prob / total_prob * 100 Then
  62.                 Cells(i + 1, 3) = "S!(g)"
  63.                 numpull = i
  64.             End If
  65.         End If
  66.     End If
  67.     '100 guarantee
  68.    If i >= 100 Then
  69.         If Excel.WorksheetFunction.CountA(Range(Cells(i - 98, 3), Cells(i, 3))) = 0 Then
  70.             Cells(i + 1, 3) = "S!(100g)"
  71.             numpull = i
  72.         End If
  73.     End If
  74.  
  75.     i = i + 1
  76.     Loop
  77.     Cells(j + 1, 4).Value = numpull
  78. Next j
  79.  
  80.  
  81. min = WorksheetFunction.min(Range(Cells(2, 4), Cells(2 + numsimul, 4)))
  82. max = WorksheetFunction.max(Range(Cells(2, 4), Cells(2 + numsimul, 4)))
  83.  
  84. k = 1
  85. Cells(k + 1, 6) = min
  86. Cells(k + 1, 7) = Application.WorksheetFunction.CountIf(Range(Cells(2, 4), Cells(2 + numsimul, 4)), min)
  87.  
  88. Do
  89.     Cells(k + 2, 6) = Cells(k + 1, 6) + 1
  90.     Cells(k + 2, 7) = Application.WorksheetFunction.CountIf(Range(Cells(2, 4), Cells(2 + numsimul, 4)), Cells(k + 2, 6).Value)
  91.     k = k + 1
  92. Loop Until k >= max - min + 1
  93.  
  94. Application.ScreenUpdating = True
  95. Runtime = Timer - Start
  96. MsgBox (Runtime)
  97.  
  98.  
  99. End Sub
  100.  
  101. Sub A2sim()
  102.  
  103. Dim numpull As Long
  104. Dim numsimul As Long
  105. Dim i As Long
  106. Dim j As Long
  107. Dim k As Integer
  108. Dim min As Long
  109. Dim max As Long
  110. Dim A_prob As Double
  111. Dim S_prob As Double
  112. Dim total_prob As Double
  113. Dim got_S As Integer
  114.  
  115. Dim Start As Single
  116. Dim Runtime As Single
  117. Dim ElapsedTime As String
  118.  
  119.  
  120. numsimul = InputBox("Number of simulations to run")
  121. S_prob = 1.5
  122. A_prob = 13.5
  123. total_prob = A_prob + S_prob '15
  124. got_S = 0
  125.  
  126. Start = Timer
  127.  
  128.  
  129. Range("A2:Z1000000").ClearContents
  130. numpull = 0
  131.  
  132.  
  133. Application.ScreenUpdating = False
  134. For j = 1 To numsimul
  135.     Range("A2:C1000000").ClearContents
  136.     numpull = 0
  137.     got_S = 0
  138.  
  139.     i = 1
  140.     Do While numpull = 0
  141.     Cells(i + 1, 1) = "=RAND()"
  142.     Cells(i + 1, 1).Value = Cells(i + 1, 1).Value * 100
  143.     Cells(i + 1, 2).Value = 0
  144.     'general
  145.    If Cells(i + 1, 1).Value <= total_prob Then
  146.         Cells(i + 1, 2).Value = 1
  147.     End If
  148.     If Cells(i + 1, 1).Value <= S_prob Then
  149.         Cells(i + 1, 3) = "S!"
  150.         numpull = i
  151.     End If
  152.     '10 guarantee
  153.    If i >= 10 And Cells(i + 1, 1).Value > total_prob Then
  154.         If Excel.WorksheetFunction.Sum(Range(Cells(i - 8, 2), Cells(i, 2))) = 0 Then
  155.             'here we're assuming that on the guarantee, the chances to get S rank vs A rank are proportional to the number of valks in the pool (1 S, 4 A rank)
  156.            Cells(i + 1, 1) = "=RAND()"
  157.             Cells(i + 1, 1).Value = Cells(i + 1, 1).Value * 100
  158.             Cells(i + 1, 2).Value = 1
  159.             If Cells(i + 1, 1).Value <= 1 / 5 * 100 Then
  160.                 Cells(i + 1, 3) = "S!(g)"
  161.                 numpull = i
  162.             End If
  163.         End If
  164.     End If
  165.     '100 guarantee
  166.    If i >= 100 Then
  167.         If Excel.WorksheetFunction.CountA(Range(Cells(i - 98, 3), Cells(i, 3))) = 0 Then
  168.             Cells(i + 1, 3) = "S!(100g)"
  169.             numpull = i
  170.         End If
  171.     End If
  172.  
  173.     i = i + 1
  174.     Loop
  175.     Cells(j + 1, 4).Value = numpull
  176. Next j
  177.  
  178.  
  179. min = WorksheetFunction.min(Range(Cells(2, 4), Cells(2 + numsimul, 4)))
  180. max = WorksheetFunction.max(Range(Cells(2, 4), Cells(2 + numsimul, 4)))
  181.  
  182. k = 1
  183. Cells(k + 1, 6) = min
  184. Cells(k + 1, 7) = Application.WorksheetFunction.CountIf(Range(Cells(2, 4), Cells(2 + numsimul, 4)), min)
  185.  
  186. Do
  187.     Cells(k + 2, 6) = Cells(k + 1, 6) + 1
  188.     Cells(k + 2, 7) = Application.WorksheetFunction.CountIf(Range(Cells(2, 4), Cells(2 + numsimul, 4)), Cells(k + 2, 6).Value)
  189.     k = k + 1
  190. Loop Until k >= max - min + 1
  191.  
  192. Application.ScreenUpdating = True
  193. Runtime = Timer - Start
  194. MsgBox (Runtime)
  195.  
  196.  
  197. End Sub
  198.  
  199. Sub A3sim()
  200.  
  201. Dim numpull As Long
  202. Dim numsimul As Long
  203. Dim i As Long
  204. Dim j As Long
  205. Dim k As Integer
  206. Dim min As Long
  207. Dim max As Long
  208. Dim A_prob As Double
  209. Dim S_prob As Double
  210. Dim total_prob As Double
  211. Dim got_S As Integer
  212.  
  213. Dim Start As Single
  214. Dim Runtime As Single
  215. Dim ElapsedTime As String
  216.  
  217.  
  218. numsimul = InputBox("Number of simulations to run")
  219. S_prob = 1.5
  220. A_prob = 13.5
  221. total_prob = A_prob + S_prob '15
  222. got_S = 0
  223.  
  224. Start = Timer
  225.  
  226.  
  227. Range("A2:Z1000000").ClearContents
  228. numpull = 0
  229.  
  230.  
  231. Application.ScreenUpdating = False
  232. For j = 1 To numsimul
  233.     Range("A2:C1000000").ClearContents
  234.     numpull = 0
  235.     got_S = 0
  236.  
  237.     i = 1
  238.     Do While numpull = 0
  239.     Cells(i + 1, 1) = "=RAND()"
  240.     Cells(i + 1, 1).Value = Cells(i + 1, 1).Value * 100
  241.     Cells(i + 1, 2).Value = 0
  242.     'general
  243.    If Cells(i + 1, 1).Value <= total_prob Then
  244.         Cells(i + 1, 2).Value = 1
  245.     End If
  246.     If Cells(i + 1, 1).Value <= S_prob Then
  247.         Cells(i + 1, 3) = "S!"
  248.         numpull = i
  249.     End If
  250.     '10 guarantee
  251.    If i >= 10 And Cells(i + 1, 1).Value > total_prob Then
  252.         If Excel.WorksheetFunction.Sum(Range(Cells(i - 8, 2), Cells(i, 2))) = 0 Then
  253.             'here we're assuming that on the guarantee, the chances to get S rank vs A rank are equal to the listed rates (i.e. 1.5% for S, 98.5% for A)
  254.            Cells(i + 1, 1) = "=RAND()"
  255.             Cells(i + 1, 1).Value = Cells(i + 1, 1).Value * 100
  256.             Cells(i + 1, 2).Value = 1
  257.             If Cells(i + 1, 1).Value <= S_prob Then
  258.                 Cells(i + 1, 3) = "S!(g)"
  259.                 numpull = i
  260.             End If
  261.         End If
  262.     End If
  263.     '100 guarantee
  264.    If i >= 100 Then
  265.         If Excel.WorksheetFunction.CountA(Range(Cells(i - 98, 3), Cells(i, 3))) = 0 Then
  266.             Cells(i + 1, 3) = "S!(100g)"
  267.             numpull = i
  268.         End If
  269.     End If
  270.  
  271.     i = i + 1
  272.     Loop
  273.     Cells(j + 1, 4).Value = numpull
  274. Next j
  275.  
  276.  
  277. min = WorksheetFunction.min(Range(Cells(2, 4), Cells(2 + numsimul, 4)))
  278. max = WorksheetFunction.max(Range(Cells(2, 4), Cells(2 + numsimul, 4)))
  279.  
  280. k = 1
  281. Cells(k + 1, 6) = min
  282. Cells(k + 1, 7) = Application.WorksheetFunction.CountIf(Range(Cells(2, 4), Cells(2 + numsimul, 4)), min)
  283.  
  284. Do
  285.     Cells(k + 2, 6) = Cells(k + 1, 6) + 1
  286.     Cells(k + 2, 7) = Application.WorksheetFunction.CountIf(Range(Cells(2, 4), Cells(2 + numsimul, 4)), Cells(k + 2, 6).Value)
  287.     k = k + 1
  288. Loop Until k >= max - min + 1
  289.  
  290. Application.ScreenUpdating = True
  291. Runtime = Timer - Start
  292. MsgBox (Runtime)
  293.  
  294.  
  295. End Sub
  296.  
  297. Sub B3sim()
  298.  
  299. Dim numpull As Long
  300. Dim numsimul As Long
  301. Dim i As Long
  302. Dim j As Long
  303. Dim k As Integer
  304. Dim min As Long
  305. Dim max As Long
  306. Dim A_prob As Double
  307. Dim S_prob As Double
  308. Dim total_prob As Double
  309. Dim got_S As Integer
  310.  
  311. Dim Start As Single
  312. Dim Runtime As Single
  313. Dim ElapsedTime As String
  314.  
  315.  
  316. numsimul = InputBox("Number of simulations to run")
  317. S_prob = 1.5 * 0.5
  318. A_prob = 13.5 * 0.5
  319. total_prob = A_prob + S_prob '15
  320. got_S = 0
  321.  
  322. Start = Timer
  323.  
  324.  
  325. Range("A2:Z1000000").ClearContents
  326. numpull = 0
  327.  
  328.  
  329. Application.ScreenUpdating = False
  330. For j = 1 To numsimul
  331.     Range("A2:C1000000").ClearContents
  332.     numpull = 0
  333.     got_S = 0
  334.  
  335.     i = 1
  336.     Do While numpull = 0
  337.     Cells(i + 1, 1) = "=RAND()"
  338.     Cells(i + 1, 1).Value = Cells(i + 1, 1).Value * 100
  339.     Cells(i + 1, 2).Value = 0
  340.     'general
  341.    If Cells(i + 1, 1).Value <= total_prob Then
  342.         Cells(i + 1, 2).Value = 1
  343.     End If
  344.     If Cells(i + 1, 1).Value <= S_prob Then
  345.         Cells(i + 1, 3) = "S!"
  346.         numpull = i
  347.     End If
  348.     '10 guarantee
  349.    If i >= 10 And Cells(i + 1, 1).Value > total_prob Then
  350.         If Excel.WorksheetFunction.Sum(Range(Cells(i - 8, 2), Cells(i, 2))) = 0 Then
  351.             'here we're assuming that on the guarantee, the chances to get S rank vs A rank are equal to the listed rates (i.e. 1.5% for S, 98.5% for A)
  352.            Cells(i + 1, 1) = "=RAND()"
  353.             Cells(i + 1, 1).Value = Cells(i + 1, 1).Value * 100
  354.             Cells(i + 1, 2).Value = 1
  355.             If Cells(i + 1, 1).Value <= S_prob Then
  356.                 Cells(i + 1, 3) = "S!(g)"
  357.                 numpull = i
  358.             End If
  359.         End If
  360.     End If
  361.     '100 guarantee
  362.    If i >= 100 Then
  363.         If Excel.WorksheetFunction.CountA(Range(Cells(i - 98, 3), Cells(i, 3))) = 0 Then
  364.             Cells(i + 1, 3) = "S!(100g)"
  365.             numpull = i
  366.         End If
  367.     End If
  368.  
  369.     i = i + 1
  370.     Loop
  371.     Cells(j + 1, 4).Value = numpull
  372. Next j
  373.  
  374.  
  375. min = WorksheetFunction.min(Range(Cells(2, 4), Cells(2 + numsimul, 4)))
  376. max = WorksheetFunction.max(Range(Cells(2, 4), Cells(2 + numsimul, 4)))
  377.  
  378. k = 1
  379. Cells(k + 1, 6) = min
  380. Cells(k + 1, 7) = Application.WorksheetFunction.CountIf(Range(Cells(2, 4), Cells(2 + numsimul, 4)), min)
  381.  
  382. Do
  383.     Cells(k + 2, 6) = Cells(k + 1, 6) + 1
  384.     Cells(k + 2, 7) = Application.WorksheetFunction.CountIf(Range(Cells(2, 4), Cells(2 + numsimul, 4)), Cells(k + 2, 6).Value)
  385.     k = k + 1
  386. Loop Until k >= max - min + 1
  387.  
  388. Application.ScreenUpdating = True
  389. Runtime = Timer - Start
  390. MsgBox (Runtime)
  391.  
  392.  
  393. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement