@stdlib/random-base 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -181,32 +181,6 @@ The library links against the following external libraries or contains
181
181
  implementations from the following external libraries, which have their own
182
182
  licenses:
183
183
 
184
- * Boost <http://www.boost.org/LICENSE_1_0.txt>
185
-
186
- Boost Software License - Version 1.0 - August 17th, 2003
187
-
188
- Permission is hereby granted, free of charge, to any person or organization
189
- obtaining a copy of the software and accompanying documentation covered by
190
- this license (the "Software") to use, reproduce, display, distribute,
191
- execute, and transmit the Software, and to prepare derivative works of the
192
- Software, and to permit third-parties to whom the Software is furnished to
193
- do so, all subject to the following:
194
-
195
- The copyright notices in the Software and this entire statement, including
196
- the above license grant, this restriction and the following disclaimer,
197
- must be included in all copies of the Software, in whole or in part, and
198
- all derivative works of the Software, unless such copies or derivative
199
- works are solely in the form of machine-executable object code generated by
200
- a source language processor.
201
-
202
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
203
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
204
- FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
205
- SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
206
- FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
207
- ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
208
- DEALINGS IN THE SOFTWARE.
209
-
210
184
  * MT19937 <http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/
211
185
  mt19937ar.c>
212
186
 
@@ -240,3 +214,29 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
240
214
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
241
215
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
242
216
 
217
+ * Boost <http://www.boost.org/LICENSE_1_0.txt>
218
+
219
+ Boost Software License - Version 1.0 - August 17th, 2003
220
+
221
+ Permission is hereby granted, free of charge, to any person or organization
222
+ obtaining a copy of the software and accompanying documentation covered by
223
+ this license (the "Software") to use, reproduce, display, distribute,
224
+ execute, and transmit the Software, and to prepare derivative works of the
225
+ Software, and to permit third-parties to whom the Software is furnished to
226
+ do so, all subject to the following:
227
+
228
+ The copyright notices in the Software and this entire statement, including
229
+ the above license grant, this restriction and the following disclaimer,
230
+ must be included in all copies of the Software, in whole or in part, and
231
+ all derivative works of the Software, unless such copies or derivative
232
+ works are solely in the form of machine-executable object code generated by
233
+ a source language processor.
234
+
235
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
236
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
237
+ FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
238
+ SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
239
+ FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
240
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
241
+ DEALINGS IN THE SOFTWARE.
242
+
package/NOTICE CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2023 The Stdlib Authors.
1
+ Copyright (c) 2016-2024 The Stdlib Authors.
package/README.md CHANGED
@@ -223,7 +223,7 @@ See [LICENSE][stdlib-license].
223
223
 
224
224
  ## Copyright
225
225
 
226
- Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
226
+ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
227
227
 
228
228
  </section>
229
229
 
@@ -236,8 +236,8 @@ Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
236
236
  [npm-image]: http://img.shields.io/npm/v/@stdlib/random-base.svg
237
237
  [npm-url]: https://npmjs.org/package/@stdlib/random-base
238
238
 
239
- [test-image]: https://github.com/stdlib-js/random-base/actions/workflows/test.yml/badge.svg?branch=v0.1.1
240
- [test-url]: https://github.com/stdlib-js/random-base/actions/workflows/test.yml?query=branch:v0.1.1
239
+ [test-image]: https://github.com/stdlib-js/random-base/actions/workflows/test.yml/badge.svg?branch=v0.2.1
240
+ [test-url]: https://github.com/stdlib-js/random-base/actions/workflows/test.yml?query=branch:v0.2.1
241
241
 
242
242
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/random-base/main.svg
243
243
  [coverage-url]: https://codecov.io/github/stdlib-js/random-base?branch=main
@@ -260,8 +260,11 @@ Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
260
260
  [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
261
261
 
262
262
  [deno-url]: https://github.com/stdlib-js/random-base/tree/deno
263
+ [deno-readme]: https://github.com/stdlib-js/random-base/blob/deno/README.md
263
264
  [umd-url]: https://github.com/stdlib-js/random-base/tree/umd
265
+ [umd-readme]: https://github.com/stdlib-js/random-base/blob/umd/README.md
264
266
  [esm-url]: https://github.com/stdlib-js/random-base/tree/esm
267
+ [esm-readme]: https://github.com/stdlib-js/random-base/blob/esm/README.md
265
268
  [branches-url]: https://github.com/stdlib-js/random-base/blob/main/branches.md
266
269
 
267
270
  [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/random-base/main/LICENSE
@@ -927,8 +927,8 @@ interface Namespace {
927
927
  * @returns value or PRNG
928
928
  *
929
929
  * @example
930
- * var parseJSON = require( `@stdlib/utils/parse-json` );
931
- * var mt19937 = require( `@stdlib/random/base/mt19937` );
930
+ * var parseJSON = require( '@stdlib/utils-parse-json' );
931
+ * var mt19937 = require( '@stdlib/random-base-mt19937' );
932
932
  *
933
933
  * var str = JSON.stringify( mt19937 );
934
934
  * var rand = parseJSON( str, ns.reviveBasePRNG );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/random-base",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
4
  "description": "Base pseudorandom number generators.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -15,21 +15,12 @@
15
15
  ],
16
16
  "main": "./lib",
17
17
  "directories": {
18
- "benchmark": "./benchmark",
19
18
  "doc": "./docs",
20
- "example": "./examples",
21
- "include": "./include",
22
19
  "lib": "./lib",
23
- "src": "./src",
24
- "test": "./test"
20
+ "dist": "./dist"
25
21
  },
26
22
  "types": "./docs/types",
27
- "scripts": {
28
- "test": "make test",
29
- "test-cov": "make test-cov",
30
- "examples": "make examples",
31
- "benchmark": "make benchmark"
32
- },
23
+ "scripts": {},
33
24
  "homepage": "https://stdlib.io",
34
25
  "repository": {
35
26
  "type": "git",
@@ -39,132 +30,51 @@
39
30
  "url": "https://github.com/stdlib-js/stdlib/issues"
40
31
  },
41
32
  "dependencies": {
42
- "@stdlib/random-base-arcsine": "^0.1.0",
43
- "@stdlib/random-base-bernoulli": "^0.1.0",
44
- "@stdlib/random-base-beta": "^0.1.0",
45
- "@stdlib/random-base-betaprime": "^0.1.0",
46
- "@stdlib/random-base-binomial": "^0.1.0",
47
- "@stdlib/random-base-box-muller": "^0.1.0",
48
- "@stdlib/random-base-cauchy": "^0.1.0",
49
- "@stdlib/random-base-chi": "^0.1.0",
50
- "@stdlib/random-base-chisquare": "^0.1.0",
51
- "@stdlib/random-base-cosine": "^0.1.0",
52
- "@stdlib/random-base-discrete-uniform": "^0.1.0",
53
- "@stdlib/random-base-erlang": "^0.1.0",
54
- "@stdlib/random-base-exponential": "^0.1.0",
55
- "@stdlib/random-base-f": "^0.1.0",
56
- "@stdlib/random-base-frechet": "^0.1.0",
57
- "@stdlib/random-base-gamma": "^0.1.0",
58
- "@stdlib/random-base-geometric": "^0.1.0",
59
- "@stdlib/random-base-gumbel": "^0.1.0",
60
- "@stdlib/random-base-hypergeometric": "^0.1.0",
61
- "@stdlib/random-base-improved-ziggurat": "^0.1.0",
62
- "@stdlib/random-base-invgamma": "^0.1.0",
63
- "@stdlib/random-base-kumaraswamy": "^0.1.0",
64
- "@stdlib/random-base-laplace": "^0.1.0",
65
- "@stdlib/random-base-levy": "^0.1.0",
66
- "@stdlib/random-base-logistic": "^0.1.0",
67
- "@stdlib/random-base-lognormal": "^0.1.0",
68
- "@stdlib/random-base-minstd": "^0.1.0",
69
- "@stdlib/random-base-minstd-shuffle": "^0.1.0",
70
- "@stdlib/random-base-mt19937": "^0.1.0",
71
- "@stdlib/random-base-negative-binomial": "^0.1.0",
72
- "@stdlib/random-base-normal": "^0.1.0",
73
- "@stdlib/random-base-pareto-type1": "^0.1.0",
74
- "@stdlib/random-base-poisson": "^0.1.0",
75
- "@stdlib/random-base-randi": "^0.1.0",
76
- "@stdlib/random-base-randn": "^0.1.0",
77
- "@stdlib/random-base-randu": "^0.1.0",
78
- "@stdlib/random-base-rayleigh": "^0.1.0",
79
- "@stdlib/random-base-reviver": "^0.1.0",
80
- "@stdlib/random-base-t": "^0.1.0",
81
- "@stdlib/random-base-triangular": "^0.1.0",
82
- "@stdlib/random-base-uniform": "^0.1.0",
83
- "@stdlib/random-base-weibull": "^0.1.0",
84
- "@stdlib/utils-define-read-only-property": "^0.1.1",
85
- "@stdlib/utils-library-manifest": "^0.1.1"
86
- },
87
- "devDependencies": {
88
- "@stdlib/array-int32": "^0.1.1",
89
- "@stdlib/array-to-json": "^0.1.0",
90
- "@stdlib/array-uint32": "^0.1.1",
91
- "@stdlib/assert-contains": "^0.1.0",
92
- "@stdlib/assert-has-own-property": "^0.1.1",
93
- "@stdlib/assert-is-array": "^0.1.1",
94
- "@stdlib/assert-is-array-like-object": "^0.1.0",
95
- "@stdlib/assert-is-boolean": "^0.1.1",
96
- "@stdlib/assert-is-collection": "^0.1.0",
97
- "@stdlib/assert-is-function": "^0.1.1",
98
- "@stdlib/assert-is-int32array": "^0.1.1",
99
- "@stdlib/assert-is-integer": "^0.1.0",
100
- "@stdlib/assert-is-nan": "^0.1.1",
101
- "@stdlib/assert-is-nonnegative-integer": "^0.1.0",
102
- "@stdlib/assert-is-number": "^0.1.1",
103
- "@stdlib/assert-is-plain-object": "^0.1.1",
104
- "@stdlib/assert-is-positive-integer": "^0.1.0",
105
- "@stdlib/assert-is-positive-number": "^0.1.1",
106
- "@stdlib/assert-is-prng-like": "^0.1.1",
107
- "@stdlib/assert-is-probability": "^0.1.1",
108
- "@stdlib/assert-is-string": "^0.1.1",
109
- "@stdlib/assert-is-uint32array": "^0.1.1",
110
- "@stdlib/blas-base-gcopy": "^0.1.0",
111
- "@stdlib/constants-float64-eps": "^0.1.1",
112
- "@stdlib/constants-float64-half-pi": "^0.1.1",
113
- "@stdlib/constants-float64-ln-sqrt-two-pi": "^0.1.1",
114
- "@stdlib/constants-float64-max-safe-integer": "^0.1.1",
115
- "@stdlib/constants-float64-pi": "^0.1.1",
116
- "@stdlib/constants-float64-pinf": "^0.1.1",
117
- "@stdlib/constants-float64-two-pi": "^0.1.1",
118
- "@stdlib/constants-int32-max": "^0.1.1",
119
- "@stdlib/constants-uint32-max": "^0.1.1",
120
- "@stdlib/fs-exists": "^0.1.1",
121
- "@stdlib/fs-read-dir": "^0.1.1",
122
- "@stdlib/fs-write-file": "^0.1.1",
123
- "@stdlib/math-base-assert-is-integer": "^0.1.1",
124
- "@stdlib/math-base-assert-is-nan": "^0.1.1",
125
- "@stdlib/math-base-assert-is-nonnegative-integer": "^0.1.1",
126
- "@stdlib/math-base-assert-is-positive-integer": "^0.1.1",
127
- "@stdlib/math-base-assert-is-probability": "^0.1.1",
128
- "@stdlib/math-base-ops-umul": "^0.1.1",
129
- "@stdlib/math-base-special-abs": "^0.1.1",
130
- "@stdlib/math-base-special-ceil": "^0.1.1",
131
- "@stdlib/math-base-special-cos": "^0.1.0",
132
- "@stdlib/math-base-special-exp": "^0.1.0",
133
- "@stdlib/math-base-special-factorial": "^0.1.0",
134
- "@stdlib/math-base-special-factorialln": "^0.1.0",
135
- "@stdlib/math-base-special-floor": "^0.1.1",
136
- "@stdlib/math-base-special-ln": "^0.1.1",
137
- "@stdlib/math-base-special-max": "^0.1.1",
138
- "@stdlib/math-base-special-pow": "^0.1.0",
139
- "@stdlib/math-base-special-round": "^0.1.1",
140
- "@stdlib/math-base-special-signum": "^0.1.1",
141
- "@stdlib/math-base-special-sin": "^0.1.0",
142
- "@stdlib/math-base-special-sqrt": "^0.1.1",
143
- "@stdlib/math-base-special-tan": "^0.1.0",
144
- "@stdlib/object-assign": "^0.1.0",
145
- "@stdlib/process-env": "^0.1.1",
146
- "@stdlib/stats-base-dists-cosine-quantile": "^0.1.0",
147
- "@stdlib/stats-base-dists-normal-quantile": "^0.1.1",
148
- "@stdlib/stats-chi2gof": "^0.1.0",
149
- "@stdlib/stats-kstest": "^0.1.0",
150
- "@stdlib/string-format": "^0.1.1",
151
- "@stdlib/time-current-year": "^0.1.1",
152
- "@stdlib/time-now": "^0.1.1",
153
- "@stdlib/utils-constant-function": "^0.1.1",
154
- "@stdlib/utils-copy": "^0.1.0",
155
- "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1",
156
- "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1",
157
- "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.1.1",
158
- "@stdlib/utils-keys": "^0.1.0",
159
- "@stdlib/utils-noop": "^0.1.1",
160
- "@stdlib/utils-parse-json": "^0.1.1",
161
- "proxyquire": "^2.0.0",
162
- "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
163
- "istanbul": "^0.4.1",
164
- "tap-min": "git+https://github.com/Planeshifter/tap-min.git",
165
- "@stdlib/bench-harness": "^0.1.2",
166
- "@stdlib/bench": "^0.2.1"
33
+ "@stdlib/random-base-arcsine": "^0.2.1",
34
+ "@stdlib/random-base-bernoulli": "^0.2.1",
35
+ "@stdlib/random-base-beta": "^0.2.1",
36
+ "@stdlib/random-base-betaprime": "^0.2.1",
37
+ "@stdlib/random-base-binomial": "^0.2.1",
38
+ "@stdlib/random-base-box-muller": "^0.2.1",
39
+ "@stdlib/random-base-cauchy": "^0.2.1",
40
+ "@stdlib/random-base-chi": "^0.2.1",
41
+ "@stdlib/random-base-chisquare": "^0.2.1",
42
+ "@stdlib/random-base-cosine": "^0.2.1",
43
+ "@stdlib/random-base-discrete-uniform": "^0.2.1",
44
+ "@stdlib/random-base-erlang": "^0.2.1",
45
+ "@stdlib/random-base-exponential": "^0.2.1",
46
+ "@stdlib/random-base-f": "^0.2.1",
47
+ "@stdlib/random-base-frechet": "^0.2.1",
48
+ "@stdlib/random-base-gamma": "^0.2.1",
49
+ "@stdlib/random-base-geometric": "^0.2.1",
50
+ "@stdlib/random-base-gumbel": "^0.2.1",
51
+ "@stdlib/random-base-hypergeometric": "^0.2.1",
52
+ "@stdlib/random-base-improved-ziggurat": "^0.2.1",
53
+ "@stdlib/random-base-invgamma": "^0.2.1",
54
+ "@stdlib/random-base-kumaraswamy": "^0.2.1",
55
+ "@stdlib/random-base-laplace": "^0.2.1",
56
+ "@stdlib/random-base-levy": "^0.2.1",
57
+ "@stdlib/random-base-logistic": "^0.2.1",
58
+ "@stdlib/random-base-lognormal": "^0.2.1",
59
+ "@stdlib/random-base-minstd": "^0.2.1",
60
+ "@stdlib/random-base-minstd-shuffle": "^0.2.1",
61
+ "@stdlib/random-base-mt19937": "^0.2.1",
62
+ "@stdlib/random-base-negative-binomial": "^0.2.1",
63
+ "@stdlib/random-base-normal": "^0.2.1",
64
+ "@stdlib/random-base-pareto-type1": "^0.2.1",
65
+ "@stdlib/random-base-poisson": "^0.2.1",
66
+ "@stdlib/random-base-randi": "^0.2.1",
67
+ "@stdlib/random-base-randn": "^0.2.1",
68
+ "@stdlib/random-base-randu": "^0.2.1",
69
+ "@stdlib/random-base-rayleigh": "^0.2.1",
70
+ "@stdlib/random-base-reviver": "^0.2.1",
71
+ "@stdlib/random-base-t": "^0.2.1",
72
+ "@stdlib/random-base-triangular": "^0.2.1",
73
+ "@stdlib/random-base-uniform": "^0.2.1",
74
+ "@stdlib/random-base-weibull": "^0.2.1",
75
+ "@stdlib/utils-define-read-only-property": "^0.2.1"
167
76
  },
77
+ "devDependencies": {},
168
78
  "engines": {
169
79
  "node": ">=0.10.0",
170
80
  "npm": ">2.7.0"
@@ -1,147 +0,0 @@
1
- /**
2
- * @license Apache-2.0
3
- *
4
- * Copyright (c) 2018 The Stdlib Authors.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
-
19
- #ifndef STDLIB_RANDOM_BASE_H
20
- #define STDLIB_RANDOM_BASE_H
21
-
22
- #include <stdlib.h>
23
- #include <stdint.h>
24
-
25
- /*
26
- * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
27
- */
28
- #ifdef __cplusplus
29
- extern "C" {
30
- #endif
31
-
32
- // Forward declaration.
33
- struct BasePRNGObject;
34
-
35
- /**
36
- * Base PRNG structure.
37
- */
38
- struct BasePRNG {
39
- // Define the generator name:
40
- const char *name;
41
-
42
- // Define the minimum possible generated integer value:
43
- const uint64_t min;
44
-
45
- // Define the maximum possible generated integer value:
46
- const uint64_t max;
47
-
48
- // Define the minimum possible generated double-precision floating-point number:
49
- const double normalized_min;
50
-
51
- // Define the maximum possible generated double-precision floating-point number:
52
- const double normalized_max;
53
-
54
- // Define the size of the PRNG state:
55
- const size_t state_size;
56
-
57
- // Define a pointer to a function for returning the next generated value:
58
- int8_t (* const next)( struct BasePRNGObject *obj, uint64_t *out );
59
-
60
- // Define a pointer to a function for returning the next generated value on the interval `[0,1)`:
61
- int8_t (* const normalized)( struct BasePRNGObject *obj, double *out );
62
-
63
- // Define a pointer to a function for freeing a PRNG's allocated memory:
64
- void (* const free)( struct BasePRNGObject *obj );
65
- };
66
-
67
- /**
68
- * Base PRNG wrapper.
69
- */
70
- struct BasePRNGObject {
71
- // Define a pointer to the underlying pseudorandom number generator:
72
- const struct BasePRNG *prng;
73
-
74
- // Define a pointer to the generator state:
75
- void *state;
76
- };
77
-
78
- /**
79
- * Frees a PRNG's allocated memory.
80
- */
81
- void stdlib_base_prng_free( struct BasePRNGObject *obj );
82
-
83
- /**
84
- * Returns a pseudorandom integer.
85
- */
86
- uint64_t stdlib_base_prng_next( struct BasePRNGObject *obj );
87
-
88
- /**
89
- * Returns a pseudorandom double-precision floating-point number on the interval `[0,1)`.
90
- */
91
- double stdlib_base_prng_normalized( struct BasePRNGObject *obj );
92
-
93
- /**
94
- * Returns a PRNG name.
95
- */
96
- const char * stdlib_base_prng_name( const struct BasePRNGObject *obj );
97
-
98
- /**
99
- * Returns the minimum possible integer value generated by a provided PRNG.
100
- */
101
- uint64_t stdlib_base_prng_min( const struct BasePRNGObject *obj );
102
-
103
- /**
104
- * Returns the maximum possible integer value generated by a provided PRNG.
105
- */
106
- uint64_t stdlib_base_prng_max( const struct BasePRNGObject *obj );
107
-
108
- /**
109
- * Returns the minimum possible double-precision floating-point number generated by a provided PRNG.
110
- */
111
- double stdlib_base_prng_normalized_min( const struct BasePRNGObject *obj );
112
-
113
- /**
114
- * Returns the maximum possible double-precision floating-point number generated by a provided PRNG.
115
- */
116
- double stdlib_base_prng_normalized_max( const struct BasePRNGObject *obj );
117
-
118
- /**
119
- * Returns the size of a provided PRNG's internal state.
120
- */
121
- size_t stdlib_base_prng_state_size( const struct BasePRNGObject *obj );
122
-
123
- /**
124
- * Returns a copy of a PRNG's internal state.
125
- */
126
- void * stdlib_base_prng_state( const struct BasePRNGObject *obj );
127
-
128
- /**
129
- * Sets a PRNG's state.
130
- */
131
- int8_t stdlib_base_prng_set( struct BasePRNGObject *obj, const void *vstate );
132
-
133
- /**
134
- * Copies a PRNG.
135
- */
136
- struct BasePRNGObject * stdlib_base_prng_copy( const struct BasePRNGObject *src );
137
-
138
- /**
139
- * Copies a PRNG state from a source PRNG to a destination PRNG of the same kind.
140
- */
141
- int8_t stdlib_base_prng_copy_state( struct BasePRNGObject *dest, const struct BasePRNGObject *src );
142
-
143
- #ifdef __cplusplus
144
- }
145
- #endif
146
-
147
- #endif // !STDLIB_RANDOM_BASE_H
package/manifest.json DELETED
@@ -1,38 +0,0 @@
1
- {
2
- "options": {},
3
- "fields": [
4
- {
5
- "field": "src",
6
- "resolve": true,
7
- "relative": true
8
- },
9
- {
10
- "field": "include",
11
- "resolve": true,
12
- "relative": true
13
- },
14
- {
15
- "field": "libraries",
16
- "resolve": false,
17
- "relative": false
18
- },
19
- {
20
- "field": "libpath",
21
- "resolve": true,
22
- "relative": false
23
- }
24
- ],
25
- "confs": [
26
- {
27
- "src": [
28
- "./src/main.c"
29
- ],
30
- "include": [
31
- "./include"
32
- ],
33
- "libraries": [],
34
- "libpath": [],
35
- "dependencies": []
36
- }
37
- ]
38
- }
package/src/main.c DELETED
@@ -1,223 +0,0 @@
1
- /**
2
- * @license Apache-2.0
3
- *
4
- * Copyright (c) 2018 The Stdlib Authors.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
-
19
- // Note: keep project includes in alphabetical order...
20
- #include <stdlib.h>
21
- #include <stdint.h>
22
- #include <string.h>
23
- #include <math.h>
24
- #include "stdlib/random/base.h"
25
-
26
- /**
27
- * Frees a PRNG's allocated memory.
28
- *
29
- * @param obj PRNG object
30
- */
31
- void stdlib_base_prng_free( struct BasePRNGObject *obj ) {
32
- if ( obj == NULL ) {
33
- return;
34
- }
35
- obj->prng->free( obj );
36
- }
37
-
38
- /**
39
- * Returns a pseudorandom integer.
40
- *
41
- * ## Notes
42
- *
43
- * - The function returns `0` if provided a `NULL` pointer.
44
- *
45
- * @param obj PRNG object
46
- * @return pseudorandom integer
47
- */
48
- uint64_t stdlib_base_prng_next( struct BasePRNGObject *obj ) {
49
- if ( obj == NULL ) {
50
- return 0;
51
- }
52
- uint64_t v;
53
- obj->prng->next( obj, &v );
54
- return v;
55
- }
56
-
57
- /**
58
- * Returns a pseudorandom double-precision floating-point number on the interval `[0,1)`.
59
- *
60
- * ## Notes
61
- *
62
- * - The function returns `NAN` if provided a `NULL` pointer.
63
- *
64
- * @param obj PRNG object
65
- * @return pseudorandom number
66
- */
67
- double stdlib_base_prng_normalized( struct BasePRNGObject *obj ) {
68
- if ( obj == NULL ) {
69
- return NAN;
70
- }
71
- double v;
72
- obj->prng->normalized( obj, &v );
73
- return v;
74
- }
75
-
76
- /**
77
- * Returns a PRNG name.
78
- *
79
- * @param obj PRNG object
80
- * @return PRNG name
81
- */
82
- const char * stdlib_base_prng_name( const struct BasePRNGObject *obj ) {
83
- return obj->prng->name;
84
- }
85
-
86
- /**
87
- * Returns the minimum possible integer value generated by a provided PRNG.
88
- *
89
- * @param obj PRNG object
90
- * @return minimum possible integer value
91
- */
92
- uint64_t stdlib_base_prng_min( const struct BasePRNGObject *obj ) {
93
- return (uint64_t)( obj->prng->min );
94
- }
95
-
96
- /**
97
- * Returns the maximum possible integer value generated by a provided PRNG.
98
- *
99
- * @param obj PRNG object
100
- * @return maximum possible integer value
101
- */
102
- uint64_t stdlib_base_prng_max( const struct BasePRNGObject *obj ) {
103
- return (uint64_t)( obj->prng->max );
104
- }
105
-
106
- /**
107
- * Returns the minimum possible double-precision floating-point number generated by a provided PRNG.
108
- *
109
- * @param obj PRNG object
110
- * @return minimum possible double
111
- */
112
- double stdlib_base_prng_normalized_min( const struct BasePRNGObject *obj ) {
113
- return (double)( obj->prng->normalized_min );
114
- }
115
-
116
- /**
117
- * Returns the maximum possible double-precision floating-point number generated by a provided PRNG.
118
- *
119
- * @param obj PRNG object
120
- * @return maximum possible double
121
- */
122
- double stdlib_base_prng_normalized_max( const struct BasePRNGObject *obj ) {
123
- return (double)( obj->prng->normalized_max );
124
- }
125
-
126
- /**
127
- * Returns the size of a provided PRNG's internal state.
128
- *
129
- * @param obj PRNG object
130
- * @return state size
131
- */
132
- size_t stdlib_base_prng_state_size( const struct BasePRNGObject *obj ) {
133
- return (size_t)( obj->prng->state_size );
134
- }
135
-
136
- /**
137
- * Returns a copy of a PRNG's internal state.
138
- *
139
- * ## Notes
140
- *
141
- * - The user is responsible for freeing the allocated memory.
142
- *
143
- * @param obj PRNG object
144
- * @return pointer to a copy of a PRNG's internal state or, if unable to allocate memory, a null pointer
145
- */
146
- void * stdlib_base_prng_state( const struct BasePRNGObject *obj ) {
147
- if ( obj == NULL ) {
148
- return NULL;
149
- }
150
- void *state = malloc( obj->prng->state_size );
151
- if ( state == NULL ) {
152
- return NULL;
153
- }
154
- memcpy( state, obj->state, obj->prng->state_size );
155
- return state;
156
- }
157
-
158
- /**
159
- * Sets a PRNG's state.
160
- *
161
- * ## Notes
162
- *
163
- * - The function returns `-1` if unable to set a PRNG state and `0` otherwise.
164
- *
165
- * @param obj PRNG object
166
- * @param state state
167
- * @return status code
168
- */
169
- int8_t stdlib_base_prng_set( struct BasePRNGObject *obj, const void *vstate ) {
170
- if ( obj == NULL || vstate == NULL ) {
171
- return -1;
172
- }
173
- memcpy( obj->state, vstate, obj->prng->state_size );
174
- return 0;
175
- }
176
-
177
- /**
178
- * Copies a PRNG.
179
- *
180
- * @param src source PRNG object
181
- * @return pointer to a dynamically allocated PRNG or, if unable to allocate memory, a null pointer
182
- */
183
- struct BasePRNGObject * stdlib_base_prng_copy( const struct BasePRNGObject *src ) {
184
- struct BasePRNGObject *out = (struct BasePRNGObject *)malloc( sizeof( struct BasePRNGObject ) );
185
- if ( out == NULL ) {
186
- return NULL;
187
- }
188
- // Allocate memory for the PRNG state...
189
- out->state = malloc( src->prng->state_size );
190
- if ( out->state == NULL ) {
191
- free( out ); // prevent memory leaks
192
- return NULL;
193
- }
194
- // Set the PRNG (includes PRNG properties and methods):
195
- out->prng = src->prng;
196
-
197
- // Copy the current source PRNG state:
198
- memcpy( out->state, src->state, src->prng->state_size );
199
-
200
- return out;
201
- }
202
-
203
- /**
204
- * Copies a PRNG state from a source PRNG to a destination PRNG of the same kind.
205
- *
206
- * ## Notes
207
- *
208
- * - The function returns `-1` if unable to copy a PRNG's state and `0` otherwise.
209
- *
210
- * @param dest destination PRNG object
211
- * @param src source PRNG object
212
- * @return status code
213
- */
214
- int8_t stdlib_base_prng_copy_state( struct BasePRNGObject *dest, const struct BasePRNGObject *src ) {
215
- // We can only copy state between compatible PRNGs...
216
- if ( dest->prng != src->prng ) {
217
- return -1;
218
- }
219
- // Copy the current source PRNG state:
220
- memcpy( dest->state, src->state, src->prng->state_size );
221
-
222
- return 0;
223
- }