試行回数: 10万回
EVERY | ANY | |
---|---|---|
25% | 9 | 1 |
50% | 13 | 2 |
75% | 19 | 3 |
90% | 26 | 5 |
99% | 43 | 10 |
99.9% | 60 | 15 |
worst | 99 | 23 |
avg | 14.62265 | 2.65652 |
(use srfi-42) | |
(use math.mt-random) | |
(define mt (make <mersenne-twister> :seed (sys-time))) | |
(define (gacha) | |
(mt-random-integer mt 8)) | |
(define want #b111) | |
(define (get having) | |
($ logior having $ ash 1 $ gacha)) | |
(define (have-any? having) | |
($ not $ zero? $ logand want having)) | |
(define (have-every? having) | |
($ = want $ logand want having)) | |
(define (loop pred? n having) | |
(if (pred? having) | |
n | |
(loop pred? (+ n 1) (get having)))) | |
(define ls1 (sort (list-ec (: x 0 100000) (loop have-every? 0 0)))) | |
(define ls2 (sort (list-ec (: x 0 100000) (loop have-any? 0 0)))) | |
(define (print-result label ls) | |
(print `(,label | |
"25%" ,($ list-ref ls $ floor->exact $ * 1/4 $ length ls) | |
"50%" ,($ list-ref ls $ floor->exact $ * 2/4 $ length ls) | |
"75%" ,($ list-ref ls $ floor->exact $ * 3/4 $ length ls) | |
"90%" ,($ list-ref ls $ floor->exact $ * 9/10 $ length ls) | |
"99%" ,($ list-ref ls $ floor->exact $ * 99/100 $ length ls) | |
"99.9%" ,($ list-ref ls $ floor->exact $ * 999/1000 $ length ls) | |
"worst" ,($ list-ref ls $ + -1 $ length ls) | |
"avg" ,(/. (apply + ls) (length ls)) | |
))) | |
(print-result 'EVERY ls1) | |
(print-result 'ANY ls2) |