@@ -162,7 +162,7 @@ def get_all_dtypes(
162
162
163
163
164
164
def generate_random_numpy_array (
165
- shape , dtype = None , hermitian = False , seed_value = None
165
+ shape , dtype = None , hermitian = False , seed_value = None , low = - 10 , high = 10
166
166
):
167
167
"""
168
168
Generate a random numpy array with the specified shape and dtype.
@@ -177,13 +177,19 @@ def generate_random_numpy_array(
177
177
dtype : str or dtype, optional
178
178
Desired data-type for the output array.
179
179
If not specified, data type will be determined by numpy.
180
- Default : None
180
+ Default : `` None``
181
181
hermitian : bool, optional
182
182
If True, generates a Hermitian (symmetric if `dtype` is real) matrix.
183
- Default : False
183
+ Default : `` False``
184
184
seed_value : int, optional
185
185
The seed value to initialize the random number generator.
186
- Default : None
186
+ Default : ``None``
187
+ low : {int, float}, optional
188
+ Lower boundary of the generated samples from a uniform distribution.
189
+ Default : ``-10``.
190
+ high : {int, float}, optional
191
+ Upper boundary of the generated samples from a uniform distribution.
192
+ Default : ``10``.
187
193
188
194
Returns
189
195
-------
@@ -197,13 +203,17 @@ def generate_random_numpy_array(
197
203
198
204
"""
199
205
206
+ if seed_value is None :
207
+ seed_value = 42
200
208
numpy .random .seed (seed_value )
201
209
202
- a = numpy .random .randn (* shape ).astype (dtype )
210
+ # dtype=int is needed for 0d arrays
211
+ size = numpy .prod (shape , dtype = int )
212
+ a = numpy .random .uniform (low , high , size ).astype (dtype )
203
213
if numpy .issubdtype (a .dtype , numpy .complexfloating ):
204
- numpy .random .seed (seed_value )
205
- a += 1j * numpy .random .randn (* shape )
214
+ a += 1j * numpy .random .uniform (low , high , size )
206
215
216
+ a = a .reshape (shape )
207
217
if hermitian and a .size > 0 :
208
218
if a .ndim > 2 :
209
219
orig_shape = a .shape
0 commit comments