16
16
* limitations under the License.
17
17
*/
18
18
19
- // Note: keep project includes in alphabetical order...
20
- #include <stdlib.h>
21
- #include <stdint.h>
22
- #include <stdarg.h>
23
- #include "stdlib/random/base.h"
19
+ #include "stdlib/random/base/randu.h"
20
+ #include "stdlib/random/base/shared.h"
24
21
#include "stdlib/random/base/minstd.h"
25
22
#include "stdlib/random/base/minstd_shuffle.h"
26
23
#include "stdlib/random/base/mt19937.h"
27
- #include "stdlib/random/base/randu.h"
24
+ #include <stdlib.h>
25
+ #include <stdint.h>
26
+ #include <stdarg.h>
28
27
29
28
// Define the default PRNG:
30
29
static const enum STDLIB_BASE_RANDOM_RANDU_PRNG STDLIB_BASE_RANDOM_RANDU_DEFAULT = STDLIB_BASE_RANDOM_RANDU_MT19937 ;
@@ -43,11 +42,11 @@ static const enum STDLIB_BASE_RANDOM_RANDU_PRNG STDLIB_BASE_RANDOM_RANDU_DEFAULT
43
42
* @return pointer to a dynamically allocated PRNG or, if unable to allocate memory, a null pointer
44
43
*
45
44
* @example
45
+ * #include "stdlib/random/base/randu.h"
46
+ * #include "stdlib/random/base/shared.h"
46
47
* #include <stdlib.h>
47
48
* #include <stdio.h>
48
49
* #include <stdint.h>
49
- * #include "stdlib/random/base.h"
50
- * #include "stdlib/random/base/randu.h"
51
50
*
52
51
* // Create a PRNG:
53
52
* struct BasePRNGObject *obj = stdlib_base_random_randu_allocate( 0 );
@@ -73,11 +72,9 @@ static const enum STDLIB_BASE_RANDOM_RANDU_PRNG STDLIB_BASE_RANDOM_RANDU_DEFAULT
73
72
*/
74
73
struct BasePRNGObject * stdlib_base_random_randu_allocate ( const int nargs , ... ) {
75
74
enum STDLIB_BASE_RANDOM_RANDU_PRNG prng ;
76
- struct BasePRNGObject * obj ;
77
-
78
75
va_list args ;
79
- va_start ( args , nargs );
80
76
77
+ va_start ( args , nargs );
81
78
if ( nargs < 1 ) {
82
79
prng = STDLIB_BASE_RANDOM_RANDU_DEFAULT ;
83
80
} else {
@@ -90,20 +87,25 @@ struct BasePRNGObject * stdlib_base_random_randu_allocate( const int nargs, ...
90
87
} else {
91
88
seed = rand ();
92
89
}
93
- obj = stdlib_base_random_minstd_allocate ( seed );
94
- } else if ( prng == STDLIB_BASE_RANDOM_RANDU_MINSTD_SHUFFLE ) {
90
+ va_end ( args );
91
+ return stdlib_base_random_minstd_allocate ( seed );
92
+ }
93
+ if ( prng == STDLIB_BASE_RANDOM_RANDU_MINSTD_SHUFFLE ) {
95
94
int32_t seed ;
96
95
if ( nargs > 1 ) {
97
96
seed = va_arg ( args , int32_t );
98
97
} else {
99
98
seed = rand ();
100
99
}
101
- obj = stdlib_base_random_minstd_shuffle_allocate ( seed );
102
- } else if ( prng == STDLIB_BASE_RANDOM_RANDU_MT19937 ) {
100
+ va_end ( args );
101
+ return stdlib_base_random_minstd_shuffle_allocate ( seed );
102
+ }
103
+ if ( prng == STDLIB_BASE_RANDOM_RANDU_MT19937 ) {
104
+ const uint32_t * seed ;
103
105
int64_t seed_length ;
104
- uint32_t * seed ;
106
+ uint32_t tseed [ 1 ] ;
105
107
if ( nargs < 2 ) {
106
- uint32_t tseed [] = { (uint32_t )rand () } ;
108
+ tseed [ 0 ] = (uint32_t )rand ();
107
109
seed = tseed ;
108
110
seed_length = 1 ;
109
111
} else if ( nargs == 3 ) {
@@ -114,13 +116,12 @@ struct BasePRNGObject * stdlib_base_random_randu_allocate( const int nargs, ...
114
116
va_end ( args );
115
117
return NULL ;
116
118
}
117
- obj = stdlib_base_random_mt19937_allocate ( seed , seed_length );
118
- } else {
119
- // How did we get here? A non-implemented PRNG?
120
- obj = NULL ;
119
+ va_end ( args );
120
+ return stdlib_base_random_mt19937_allocate ( seed , seed_length );
121
121
}
122
+ // How did we get here? A non-implemented PRNG?
122
123
va_end ( args );
123
- return obj ;
124
+ return NULL ;
124
125
}
125
126
126
127
/**
@@ -134,11 +135,11 @@ struct BasePRNGObject * stdlib_base_random_randu_allocate( const int nargs, ...
134
135
* @return pseudorandom number
135
136
*
136
137
* @example
138
+ * #include "stdlib/random/base/randu.h"
139
+ * #include "stdlib/random/base/shared.h"
137
140
* #include <stdlib.h>
138
141
* #include <stdio.h>
139
142
* #include <stdint.h>
140
- * #include "stdlib/random/base.h"
141
- * #include "stdlib/random/base/randu.h"
142
143
*
143
144
* // Create a PRNG:
144
145
* struct BasePRNGObject *obj = stdlib_base_random_randu_allocate( 0 );
@@ -172,11 +173,11 @@ double stdlib_base_random_randu( struct BasePRNGObject *obj ) {
172
173
* @param obj PRNG object
173
174
*
174
175
* @example
176
+ * #include "stdlib/random/base/randu.h"
177
+ * #include "stdlib/random/base/shared.h"
175
178
* #include <stdlib.h>
176
179
* #include <stdio.h>
177
180
* #include <stdint.h>
178
- * #include "stdlib/random/base.h"
179
- * #include "stdlib/random/base/randu.h"
180
181
*
181
182
* // Create a PRNG:
182
183
* struct BasePRNGObject *obj = stdlib_base_random_randu_allocate( 0 );
0 commit comments