diff --git a/README.md b/README.md index d50aa4c..5e0b036 100644 --- a/README.md +++ b/README.md @@ -88,8 +88,9 @@ The following is a list of supported random number generators in this package. - [ ] Knuth-TAOCP-2002 [NOT STARTED] -- [ ] Knuth-TAOCP [NOT STARTED +- [ ] Knuth-TAOCP [NOT STARTED] +- [ ] Rule 30 [NOT STARTED] ## Contributing diff --git a/docs/articles/understanding-prngs.html b/docs/articles/understanding-prngs.html index 0c26aef..5376359 100644 --- a/docs/articles/understanding-prngs.html +++ b/docs/articles/understanding-prngs.html @@ -88,7 +88,7 @@

Why use randngen

Introduction

-

Pseudo-random number generators power power much of what goes on +

Pseudo-random number generators (PRNGs) power much of what goes on “behind the scenes” in statistical and cryptographic settings. In R, there is a pseudo-random number generator present which allows users to generate random variables from a variety of @@ -96,25 +96,47 @@

Introduction
 # Using version 4.2.2 (at time of writing)
+# Returns the methods used for
+# 1. The "default" random number generation, 
+# 2. Normal variable generation 
+# 3. Discrete uniform variable generation
 
 RNGkind()
 #> [1] "Mersenne-Twister" "Inversion"        "Rejection"

The PRNG which R utilizes can be specified by specifying a -.Random.seed argument in the beginning of the R script or -by adjusting the default kind (and normal.kind +.Random.seed argument in the beginning of an R script or by +adjusting the default kind (and normal.kind and sample.kind) arguments in the RNGkind or set.seed argument.

While it is possible for one to utilize their own PRNG through use of user-supplied random number generation, such an approach is -pedagogically complex and for users interested in working with random -number generation and still leaves abstraction around how random numbers -are generated from the seed and parameters supplied.

- - +pedagogically complex. For users interested in working with and learning +about random number generation, present tools available still leave a +degree of complexity and/or mystery around how random numbers are +generated from the seed(s) and parameters supplied to a given PRNG. The +randngen package provides a suite of PRNGs to which aim to +be easy to use and flexible for understanding the relevant maths and +algorithms implemented by allowing users to specify all relevant +parameters.

+ +
+

From PRNG to Uniform Random Variables (and beyond!) +

+
+library(randngen)
+
+range01 <- function(x){(x-min(x))/(max(x)-min(x))}
+
+
+randngen::lcg(seed = 1234, n=10000)|>
+  range01()|>
+  hist()
+

+
+set.seed(1234)
+runif(10000)|>
+  hist()
+

References diff --git a/docs/articles/understanding-prngs_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/understanding-prngs_files/figure-html/unnamed-chunk-4-1.png new file mode 100644 index 0000000..6ff6ac0 Binary files /dev/null and b/docs/articles/understanding-prngs_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/understanding-prngs_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/understanding-prngs_files/figure-html/unnamed-chunk-5-1.png new file mode 100644 index 0000000..f350063 Binary files /dev/null and b/docs/articles/understanding-prngs_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/index.html b/docs/index.html index 68b42c5..fba8684 100644 --- a/docs/index.html +++ b/docs/index.html @@ -131,7 +131,8 @@

Random Number Genera
  • -
  • +
  • +
  • diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index c1d6751..c4f8736 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -3,5 +3,5 @@ pkgdown: 2.0.7 pkgdown_sha: ~ articles: understanding-prngs: understanding-prngs.html -last_built: 2024-10-28T03:55Z +last_built: 2024-10-28T23:48Z diff --git a/vignettes/understanding-prngs.Rmd b/vignettes/understanding-prngs.Rmd index 27dd140..c9a35df 100644 --- a/vignettes/understanding-prngs.Rmd +++ b/vignettes/understanding-prngs.Rmd @@ -21,26 +21,43 @@ library(randngen) # Introduction -Pseudo-random number generators power power much of what goes on "behind the scenes" in statistical and cryptographic settings. In `R`, there is a pseudo-random number generator present which allows users to generate random variables from a variety of distributions. To check the default PRNG used by your `R` version you can run the following: +Pseudo-random number generators (PRNGs) power much of what goes on "behind the scenes" in statistical and cryptographic settings. In `R`, there is a pseudo-random number generator present which allows users to generate random variables from a variety of distributions. To check the default PRNG used by your `R` version you can run the following: ```{r} # Using version 4.2.2 (at time of writing) +# Returns the methods used for +# 1. The "default" random number generation, +# 2. Normal variable generation +# 3. Discrete uniform variable generation RNGkind() ``` -The PRNG which R utilizes can be specified by specifying a `.Random.seed` argument in the beginning of the R script or by adjusting the default `kind` (and `normal.kind` and `sample.kind`) arguments in the `RNGkind` or `set.seed` argument. +The PRNG which R utilizes can be specified by specifying a `.Random.seed` argument in the beginning of an R script or by adjusting the default `kind` (and `normal.kind` and `sample.kind`) arguments in the `RNGkind` or `set.seed` argument. -While it is possible for one to utilize their own PRNG through use of user-supplied random number generation, such an approach is pedagogically complex and for users interested in working with random number generation and still leaves abstraction around how random numbers are generated from the seed and parameters supplied. +While it is possible for one to utilize their own PRNG through use of user-supplied random number generation, such an approach is pedagogically complex. For users interested in working with and learning about random number generation, present tools available still leave a degree of complexity and/or mystery around how random numbers are generated from the seed(s) and parameters supplied to a given PRNG. The `randngen` package provides a suite of PRNGs to which aim to be easy to use and flexible for understanding the relevant maths and algorithms implemented by allowing users to specify all relevant parameters. - - + +```{r} +library(randngen) + +range01 <- function(x){(x-min(x))/(max(x)-min(x))} + + +randngen::lcg(seed = 1234, n=10000)|> + range01()|> + hist() +``` + +```{r} +set.seed(1234) +runif(10000)|> + hist() +``` + # References