是否可以从 Rust 中用户定义的分布中采样?

Is it possible to sample from user defined distribution in Rust?

我对 Rust 很陌生。我想使用 rand 板条箱从麦克斯韦-玻尔兹曼分布中采样。可能有一种方法可以使用 rand 中尚未包含的其他发行版,但我似乎无法弄清楚如何使用。有谁知道这是否可能?

要创建自定义分布,您需要为您的类型实施 Distribution

还有另一个 crate,rand_distr,它实现了 Distribution 许多常见的概率分布,您可以使用其中任何一个作为示例。

例如this is the implementation of the Poisson distribution.

完成后,您可以考虑将 Maxwell-Boltzmann 实现贡献给 rand_distr 箱子! :)