@stdlib/random-base 0.2.0 → 0.2.2

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/NOTICE CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md CHANGED
@@ -121,7 +121,7 @@ Attached to each PRNG are the following properties:
121
121
  - **seed**: the value used to seed the PRNG.
122
122
  - **seedLength**: the length of the PRNG seed.
123
123
  - **state**: the PRNG state.
124
- - **stateLength**: the length of the PRNG state.
124
+ - **stateLength**: the length of the PRNG state.
125
125
  - **byteLength**: the size of the PRNG state.
126
126
  - **PRNG**: the underlying pseudorandom number generator.
127
127
 
@@ -223,7 +223,7 @@ See [LICENSE][stdlib-license].
223
223
 
224
224
  ## Copyright
225
225
 
226
- Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
226
+ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
227
227
 
228
228
  </section>
229
229
 
@@ -236,8 +236,8 @@ Copyright &copy; 2016-2024. 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.2.0
240
- [test-url]: https://github.com/stdlib-js/random-base/actions/workflows/test.yml?query=branch:v0.2.0
239
+ [test-image]: https://github.com/stdlib-js/random-base/actions/workflows/test.yml/badge.svg?branch=v0.2.2
240
+ [test-url]: https://github.com/stdlib-js/random-base/actions/workflows/test.yml?query=branch:v0.2.2
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
@@ -249,8 +249,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
249
249
 
250
250
  -->
251
251
 
252
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
253
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
252
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
253
+ [chat-url]: https://stdlib.zulipchat.com
254
254
 
255
255
  [stdlib]: https://github.com/stdlib-js/stdlib
256
256
 
@@ -380,7 +380,7 @@ interface Namespace {
380
380
  * // returns <number>
381
381
  *
382
382
  * @example
383
- * var myf = ns.f.ns.factory( 1.5, 1.5 );
383
+ * var myf = ns.f.factory( 1.5, 1.5 );
384
384
  *
385
385
  * var v = myf();
386
386
  * // returns <number>
@@ -1017,8 +1017,8 @@ interface Namespace {
1017
1017
  * - If `k <= 0` or `lambda <= 0`, the function returns `NaN`.
1018
1018
  * - If `k` or `lambda` is `NaN`, the function returns `NaN`.
1019
1019
  *
1020
- * @param k - scale parameter
1021
- * @param lambda - shape parameter
1020
+ * @param k - shape parameter
1021
+ * @param lambda - scale parameter
1022
1022
  * @returns pseudorandom number
1023
1023
  *
1024
1024
  * @example
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/random-base",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
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.2.0",
43
- "@stdlib/random-base-bernoulli": "^0.2.0",
44
- "@stdlib/random-base-beta": "^0.2.0",
45
- "@stdlib/random-base-betaprime": "^0.2.0",
46
- "@stdlib/random-base-binomial": "^0.2.0",
47
- "@stdlib/random-base-box-muller": "^0.2.0",
48
- "@stdlib/random-base-cauchy": "^0.2.0",
49
- "@stdlib/random-base-chi": "^0.2.0",
50
- "@stdlib/random-base-chisquare": "^0.2.0",
51
- "@stdlib/random-base-cosine": "^0.1.0",
52
- "@stdlib/random-base-discrete-uniform": "^0.2.0",
53
- "@stdlib/random-base-erlang": "^0.2.0",
54
- "@stdlib/random-base-exponential": "^0.2.0",
55
- "@stdlib/random-base-f": "^0.2.0",
56
- "@stdlib/random-base-frechet": "^0.2.0",
57
- "@stdlib/random-base-gamma": "^0.1.0",
58
- "@stdlib/random-base-geometric": "^0.2.0",
59
- "@stdlib/random-base-gumbel": "^0.2.0",
60
- "@stdlib/random-base-hypergeometric": "^0.2.0",
61
- "@stdlib/random-base-improved-ziggurat": "^0.2.0",
62
- "@stdlib/random-base-invgamma": "^0.2.0",
63
- "@stdlib/random-base-kumaraswamy": "^0.2.0",
64
- "@stdlib/random-base-laplace": "^0.2.0",
65
- "@stdlib/random-base-levy": "^0.2.0",
66
- "@stdlib/random-base-logistic": "^0.2.0",
67
- "@stdlib/random-base-lognormal": "^0.2.0",
68
- "@stdlib/random-base-minstd": "^0.2.0",
69
- "@stdlib/random-base-minstd-shuffle": "^0.2.0",
70
- "@stdlib/random-base-mt19937": "^0.2.0",
71
- "@stdlib/random-base-negative-binomial": "^0.2.0",
72
- "@stdlib/random-base-normal": "^0.2.0",
73
- "@stdlib/random-base-pareto-type1": "^0.2.0",
74
- "@stdlib/random-base-poisson": "^0.2.0",
75
- "@stdlib/random-base-randi": "^0.2.0",
76
- "@stdlib/random-base-randn": "^0.2.0",
77
- "@stdlib/random-base-randu": "^0.2.0",
78
- "@stdlib/random-base-rayleigh": "^0.2.0",
79
- "@stdlib/random-base-reviver": "^0.1.0",
80
- "@stdlib/random-base-t": "^0.2.0",
81
- "@stdlib/random-base-triangular": "^0.2.0",
82
- "@stdlib/random-base-uniform": "^0.2.0",
83
- "@stdlib/random-base-weibull": "^0.2.0",
84
- "@stdlib/utils-define-read-only-property": "^0.2.0",
85
- "@stdlib/utils-library-manifest": "^0.2.0"
86
- },
87
- "devDependencies": {
88
- "@stdlib/array-int32": "^0.2.0",
89
- "@stdlib/array-to-json": "^0.2.0",
90
- "@stdlib/array-uint32": "^0.2.0",
91
- "@stdlib/assert-contains": "^0.2.0",
92
- "@stdlib/assert-has-own-property": "^0.2.0",
93
- "@stdlib/assert-is-array": "^0.2.0",
94
- "@stdlib/assert-is-array-like-object": "^0.2.0",
95
- "@stdlib/assert-is-boolean": "^0.2.0",
96
- "@stdlib/assert-is-collection": "^0.2.0",
97
- "@stdlib/assert-is-function": "^0.2.0",
98
- "@stdlib/assert-is-int32array": "^0.2.0",
99
- "@stdlib/assert-is-integer": "^0.2.0",
100
- "@stdlib/assert-is-nan": "^0.2.0",
101
- "@stdlib/assert-is-nonnegative-integer": "^0.2.0",
102
- "@stdlib/assert-is-number": "^0.2.0",
103
- "@stdlib/assert-is-plain-object": "^0.2.0",
104
- "@stdlib/assert-is-positive-integer": "^0.2.0",
105
- "@stdlib/assert-is-positive-number": "^0.2.0",
106
- "@stdlib/assert-is-prng-like": "^0.2.0",
107
- "@stdlib/assert-is-probability": "^0.2.0",
108
- "@stdlib/assert-is-string": "^0.2.0",
109
- "@stdlib/assert-is-uint32array": "^0.2.0",
110
- "@stdlib/blas-base-gcopy": "^0.1.0",
111
- "@stdlib/constants-float64-eps": "^0.2.0",
112
- "@stdlib/constants-float64-half-pi": "^0.2.0",
113
- "@stdlib/constants-float64-ln-sqrt-two-pi": "^0.2.0",
114
- "@stdlib/constants-float64-max-safe-integer": "^0.2.0",
115
- "@stdlib/constants-float64-pi": "^0.2.0",
116
- "@stdlib/constants-float64-pinf": "^0.2.0",
117
- "@stdlib/constants-float64-two-pi": "^0.2.0",
118
- "@stdlib/constants-int32-max": "^0.2.0",
119
- "@stdlib/constants-uint32-max": "^0.2.0",
120
- "@stdlib/fs-exists": "^0.2.0",
121
- "@stdlib/fs-read-dir": "^0.2.0",
122
- "@stdlib/fs-write-file": "^0.2.0",
123
- "@stdlib/math-base-assert-is-integer": "^0.2.0",
124
- "@stdlib/math-base-assert-is-nan": "^0.2.0",
125
- "@stdlib/math-base-assert-is-nonnegative-integer": "^0.2.0",
126
- "@stdlib/math-base-assert-is-positive-integer": "^0.2.0",
127
- "@stdlib/math-base-assert-is-probability": "^0.2.0",
128
- "@stdlib/math-base-ops-umul": "^0.2.0",
129
- "@stdlib/math-base-special-abs": "^0.2.0",
130
- "@stdlib/math-base-special-ceil": "^0.2.0",
131
- "@stdlib/math-base-special-cos": "^0.2.0",
132
- "@stdlib/math-base-special-exp": "^0.2.0",
133
- "@stdlib/math-base-special-factorial": "^0.2.0",
134
- "@stdlib/math-base-special-factorialln": "^0.2.0",
135
- "@stdlib/math-base-special-floor": "^0.2.0",
136
- "@stdlib/math-base-special-ln": "^0.2.0",
137
- "@stdlib/math-base-special-max": "^0.2.0",
138
- "@stdlib/math-base-special-pow": "^0.2.0",
139
- "@stdlib/math-base-special-round": "^0.2.0",
140
- "@stdlib/math-base-special-signum": "^0.2.0",
141
- "@stdlib/math-base-special-sin": "^0.2.0",
142
- "@stdlib/math-base-special-sqrt": "^0.2.0",
143
- "@stdlib/math-base-special-tan": "^0.2.0",
144
- "@stdlib/object-assign": "^0.2.0",
145
- "@stdlib/process-env": "^0.2.0",
146
- "@stdlib/stats-base-dists-cosine-quantile": "^0.2.0",
147
- "@stdlib/stats-base-dists-normal-quantile": "^0.2.0",
148
- "@stdlib/stats-chi2gof": "^0.2.0",
149
- "@stdlib/stats-kstest": "^0.2.0",
150
- "@stdlib/string-format": "^0.2.0",
151
- "@stdlib/time-current-year": "^0.2.0",
152
- "@stdlib/time-now": "^0.2.0",
153
- "@stdlib/utils-constant-function": "^0.2.0",
154
- "@stdlib/utils-copy": "^0.2.0",
155
- "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.0",
156
- "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0",
157
- "@stdlib/utils-define-nonenumerable-read-write-accessor": "^0.2.0",
158
- "@stdlib/utils-keys": "^0.2.0",
159
- "@stdlib/utils-noop": "^0.2.0",
160
- "@stdlib/utils-parse-json": "^0.2.0",
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.2.0",
166
- "@stdlib/bench": "^0.3.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.2",
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.2"
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
- }