歪んだサイコロ
import Pkg; Pkg.add("StatsBase")
using StatsBase
import Pkg; Pkg.add("Distributions")
using Distributions
using Plots
const n6d = Dict(
1 => "⚀", #\dicei
2 => "⚁",
3 => "⚂",
4 => "⚃",
5 => "⚄",
6 => "⚅",
)
const ntrial = 10000
means = Float64[]
sizehint!(means, ntrial)
anim = @animate for t in 1:ntrial
#n1, n2, n3, n4, n5, n6 = rand(1:6, 6)
a = []
for i in 1:6
push!(a, sample(1:6, StatsBase.ProbabilityWeights([0.5, 0.01, 0.01, 0.08, 0.4])))
end
n1 , n2 , n3 , n4 , n5 , n6 = a
m = (n1 + n2 + n3 + n4 + n5 + n6)/6
title = "$t times\n"
title *= "($(n6d[n1]) + $(n6d[n2]) + $(n6d[n3]) + $(n6d[n4]) + $(n6d[n5]) + $(n6d[n6]))/6"
push!(means, m)
histogram(means, title=title, xticks=0:7, norm=:pdf, ylim=[0, 0.8], xlim=[0, 7], bins=10, legend=false)
end
gif(anim, "result6.gif")
通常のサイコロ
using Plots
const n2d = Dict(
1 => "⚀", #\dicei
2 => "⚁",
3 => "⚂",
4 => "⚃",
5 => "⚄",
6 => "⚅",
)
const ntrial = 1000
means = Float64[]
sizehint!(means, ntrial)
anim = @animate for t in 1:ntrial
n1, n2, n3, n4, n5, n6 = rand(1:6, 6)
m = (n1 + n2 + n3 + n4 + n5 + n6)/6
title = "$t times\n"
title *= "($(n2d[n1]) + $(n2d[n2]) + $(n2d[n3]) + $(n2d[n4]) + $(n2d[n5]) + $(n2d[n6]))/6"
push!(means, m)
histogram(means, title=title, xticks=0:7, norm=:pdf, ylim=[0, 0.8], xlim=[0, 7], bins=10, legend=false)
end
gif(anim, "result.gif")
コイン
others
歪んだコイン
https://zenn.dev/takilog/articles/c5d29ecbce7565
- 100daysofmakie
- Makie.jlギャラリー

