乱数網羅率
https://gyazo.com/e38d5e4216723228ff5c2f74cfa6d7cc
1~100までの乱数を何回も生成し、1~100まですべてが出現するまでの回数を数える
何度も試してその平均を求める
6(1/1+1/2+...+1/6)らしい
なんでやろ...
code:moura.js
N = 6 // サイコロ
//N = 100
MAX = N * 10
HEIGHT = MAX + 100
function setup(){
createCanvas(400,HEIGHT)
histogram = []
for(i=0;i<MAX;i++) histogrami = 0 strokeWeight(0)
total = 0
trials = 0
}
function draw(){
visited = {}
for(count=0,coverage=0;coverage<N;count++){
i = Math.floor(random(N))
}
total += count
trials += 1
background('#ffc')
fill('black')
text(今回: ${count},10,30)
text(平均: ${total/trials},70,30)
fill('blue')
for(i=N;i<MAX;i++){
rect(10,i-N+40,histogrami*2,1) }
}
code:moura.rb
trials = 10000
count = 0
(0...trials).each {
visited = {}
total = 0
while true
count += 1
i = rand(100)
total += 1
break if total == 100
end
end
}
puts count / trials
出典: 増井.icon