Julia 中一维随机游走的直方图

Histogram of the 1D-random walk in Julia

这是对 100 个 1D 随机“步行者”的模拟,每个“步行者”在一个方向或另一个方向上走 100 步“步数”+1/-1。

using Plots
init = 0
walkers = 100
walk_length = 100
walks = cumsum(vcat(fill(init, 1, walkers),               # initial state
                    rand([-1, 1], walk_length, walkers)), # vertically append move direction
               dims=1)  # cumulative sum over the first dimension to get one walk per column
plot(walks, legend=nothing)

由于许多步行者在 100 步时可以达到相同的值,我想在终点创建一个直方图,显示那里的步行者数量。
我认为可能有一个 hist() 功能,但我不确定如何实现它。

histogram(walks[end, :], bins=20, legend=nothing)