@@ -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,15 @@ def generate_random_numpy_array(
197
203
198
204
"""
199
205
200
- numpy .random .seed (seed_value )
206
+ numpy .random .seed (seed_value ) if seed_value else numpy . random . seed ( 42 )
201
207
202
- a = numpy .random .randn (* shape ).astype (dtype )
208
+ # dtype=int is needed for 0d arrays
209
+ size = numpy .prod (shape , dtype = int )
210
+ a = numpy .random .uniform (low , high , size ).astype (dtype )
203
211
if numpy .issubdtype (a .dtype , numpy .complexfloating ):
204
- numpy .random .seed (seed_value )
205
- a += 1j * numpy .random .randn (* shape )
212
+ a += 1j * numpy .random .uniform (low , high , size )
206
213
214
+ a = a .reshape (shape )
207
215
if hermitian and a .size > 0 :
208
216
if a .ndim > 2 :
209
217
orig_shape = a .shape
0 commit comments