Fast random number generator for R
https://rstub.codeberg.page/xoshiro/
- C 65.6%
- R 34.4%
| external | Initial commit | |
| inst/include | Initial commit | |
| man | Initial commit | |
| R | Initial commit | |
| src | Initial commit | |
| .gitignore | Initial commit | |
| .Rbuildignore | Initial commit | |
| _pkgdown.yml | Add pkgdown configuration | |
| DESCRIPTION | Initial commit | |
| LICENSE.md | Initial commit | |
| NAMESPACE | Initial commit | |
| README.md | Mention automatic registering in README. | |
| README.Rmd | Mention automatic registering in README. | |
| xoshiro.Rproj | Initial commit | |
xoshiro
The goal of xoshiro is to make the Xoshiro256++ PRNG available to R in a form that is suitable for parallel processing.
Installation
You can install the development version of xoshiro like so:
remotes::install_git("https://codeberg.org/rstub/xoshiro/")
Example
This is a basic example which shows you how to solve a common problem:
library(xoshiro)
library(future.apply)
#> Loading required package: future
plan(multisession)
void <- future:::parallel_rng_kind(
kind = "user",
set_kind = base::RNGkind,
next_stream = xoshiro:::next_stream,
next_substream = xoshiro:::next_substream,
is_seed = xoshiro:::is_xoshiro256pp_seed,
as_seed = xoshiro:::as_xoshiro256pp_seed
)
# identical results
future_sapply(1:8, \(x){sum(runif(1e6))}, future.packages = "xoshiro", future.seed = 42)
#> [1] 500076.5 500328.9 500158.6 499847.2 500373.7 499792.5 499822.4 499186.2
future_sapply(1:8, \(x){sum(runif(1e6))}, future.packages = "xoshiro", future.seed = 42)
#> [1] 500076.5 500328.9 500158.6 499847.2 500373.7 499792.5 499822.4 499186.2
Note that loading the package automatically registers a user-defined RNG for both uniform and normal distribution:
RNGkind()
#> [1] "user-supplied" "user-supplied" "Rejection"
This implies that all standard functions like set.seed, runif or
rnorm cn be used to interact with the RNG.