https://github.com/andrie/rng.rs
https://github.com/andrie/rng.rs
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/andrie/rng.rs
- Owner: andrie
- Created: 2024-06-26T12:18:26.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-06-26T12:18:29.000Z (11 months ago)
- Last Synced: 2025-03-03T07:23:21.004Z (3 months ago)
- Language: C
- Size: 10.7 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
## rng.rs
This is a simple Rust program that demonstrates random number generation that is identical to the default behavior of the R programming language.
This code is still very experimental, and it's on my to-do list to convert the embedded `rnorm.rs` module to a standalone crate.
The library exposes these functions:
- `runif` for a uniform distribution.
- `rnorm` for a normal distribution.
- `r_set_seed()` to set the random seed.In Rust:
```rust
r_set_seed(42);
println!("rnorm: {:.5?}", rnorm(Some(5), 0.0, 1.0));
``````
rnorm: [1.37096, -0.56470, 0.36313, 0.63286, 0.40427]
```The equivalent code in R:
``` R
set.seed(42); rnorm(5)
``````
[1] 1.3709584 -0.5646982 0.3631284 0.6328626 0.4042683
```