-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
133 lines (96 loc) · 3.83 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
---
output: rmarkdown::github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
# mlsjunkgen <img src="man/figures/logo.png" align="right" height="139" />
<!-- badges: start -->
[![R-CMD-check](https://github.com/scumdogsteev/mlsjunkgen/workflows/R-CMD-check/badge.svg)](https://github.com/scumdogsteev/mlsjunkgen/actions)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/mlsjunkgen)](https://cran.r-project.org/package=mlsjunkgen) [![Coverage Status](https://img.shields.io/coveralls/scumdogsteev/mlsjunkgen.svg)](https://coveralls.io/github/scumdogsteev/mlsjunkgen) [![RStudio CRAN mirror downloads](https://cranlogs.r-pkg.org/badges/grand-total/mlsjunkgen)](https://cran.r-project.org/package=mlsjunkgen)
<!-- badges: end -->
### Background
**`mlsjunkgen`** is a pseudo-random number generator.
#### Algorithm
For any seed values of w, x, y, z:
r<sub>i</sub> = 5.980217w<sup>2</sup> + 9.446377x<sup>0.25</sup> +
4.81379y<sup>0.33</sup> + 8.91197z<sup>0.5</sup>
r<sub>i</sub> = r<sub>i</sub> - Int(r<sub>i</sub>)
For r<sub>i</sub>+1:
w = x
x = y
y = z
z = r<sub>i</sub>
#### Analysis
This generator tends to do well with various tests for randomness (K-S, Chi
Square, test for runs up and down). It may not perform as well on other tests
(e.g., tests for runs above and below the mean), but that could relate to my
choice of seeds. As a point of reference, the period of Excel's built-in random
number generator is 16,777,216 and the MLS Junk Generator's period is something
greater than 9.9 billion (the point at which I gave up on trying to determine
it).
### Installation
* `mlsjunkgen` is available [on CRAN](https://cran.r-project.org/package=mlsjunkgen) and can be
installed accordingly:
```r
install.packages("mlsjunkgen")
library(mlsjunkgen)
```
* You can also install `mlsjunkgen` from GitHub using the `devtools` package:
```r
install.packages("devtools")
library("devtools")
install_github("scumdogsteev/mlsjunkgen")
library(mlsjunkgen)
```
### Usage
The package consists of four functions:
1. `junkgen` - generates a pseudo-random number from user-specified seeds
2. `mlsjunkgenv` - generates a vector of pseudo-random numbers by calling
`junkgen` a user-specified number of times
3. `mlsjunkgend` - generates a data frame of pseudo-random numbers by calling
`junkgen` a user-specified number of times
4. `mlsjunkgenm` - generates a user-specified size matrix of pseudo-random
numbers by calling `mlsjunkgenv` and assigning the results to a matrix
#### Examples
```{r library, echo=FALSE}
library(mlsjunkgen)
```
**`junkgen`** generates a single pseudo-random number based on four user-specified
seeds:
```{r junkgen}
w <- 1
x <- 2
y <- 3
z <- 4
junkgen(w = w, x = x, y = y, z = z)
```
**`mlsjunkgenv`** generates a vector containing a stream of `n` (default = 1)
user-specified pseudo-random numbers based on four user-specified seeds rounded
to a specified (default = 5) number of decimal places:
```{r mlsjunkgenv 1}
mlsjunkgenv(n = 10, w = w, x = x, y = y, z = z, round = 2)
```
The same example with default rounding:
```{r mlsjunkgenv 2}
mlsjunkgenv(n = 10, w = w, x = x, y = y, z = z)
```
**`mlsjunkgend`** generates a data frame containing a stream of `n` user-specified
pseudo-random numbers based on four user-specified seeds:
```{r mlsjunkgend 1}
mlsjunkgend(n = 10, w = w, x = x, y = y, z = z, round = 2)
```
The same example with default rounding:
```{r mlsjunkgend 2}
mlsjunkgend(n = 10, w = w, x = x, y = y, z = z)
```
**`mlsjunkgenm`** generates a matrix of user-specified size containing a stream
of pseudo-random numbers based on four user-specified seeds:
```{r mlsjunkgenm}
mlsjunkgenm(nrow = 5, ncol = 5, w = w, x = x, y = y, z = z, round = 3)
```