8个稳定版本 (4个主要版本)
| 4.1.0 | 2020年9月1日 |
|---|---|
| 4.0.1 | 2020年9月1日 |
| 3.0.1 | 2019年7月25日 |
| 3.0.0 | 2019年6月24日 |
| 0.1.1 | 2018年4月8日 |
#2319 in 算法
在 2 crates 中使用
12KB
156 行
pcg-rs
摘要
这是一个将C和C++的PCG随机数生成库移植到Rust的版本。
该库实现了RngCore特质,这会自动实现Rng特质,提供生成和采样随机数的标准接口。
注意:在pcg-rs的1.0.0版本中,旧的采样方法已经被弃用,请使用通过Rng特质实现的采样方法。
使用方法
此crate通过std功能提供no_std兼容性。默认启用,但如果要使用no_std,可以像这样添加包
[dependencies.pcg]
version = "4.0"
default-features = false
此crate还提供对serde的可选支持,您可以通过功能启用它
[dependencies.pcg]
version = "4.0"
features = ["std", "serde"]
示例用法
use rand::prelude::*;
use pcg::Pcg;
// Initialize the default PCG rng state
let mut rng = Pcg::default();
// Generate some boolean using the standard `gen()` method, which generates the
// appropriate type with type inference
let random_bool: bool = rng.gen();
依赖项
~230KB