0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

歪んだサイコロのgif動画

0
Posted at

歪んだサイコロ

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")

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")

result.gif

コイン

others

歪んだコイン
https://zenn.dev/takilog/articles/c5d29ecbce7565

  • 100daysofmakie
  • Makie.jlギャラリー

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?