0

I have issue i want to generate 10000 random float no's in a given range, I cannot use random module because it will always go out of my range

x=random.randrange(30.000000,40.000000,10000)

i tried this

and i'm exepcting 10,000 random float no. b/w them

3 Answers3

0

You can try to use random.uniform:

for i in range(10000):
    random.uniform(30.0, 40.0)

I see you're trying to assign the float values to x, you can do so with:

x = []
for i in range(10000):
    x.append(random.uniform(30.0, 40.0))
beh aaron
  • 168
  • 7
0

Use numpy.random.uniform:

x = np.random.uniform(30.000000, 40.000000, 10000)

array([35.8284953 , 36.31252488, 37.0409413 , ..., 39.07939188,
       33.76935076, 31.11123249])
RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105
0

You could use random.uniform like:

import random
x = [random.uniform(30.0, 40.0) for i in range(10000)]

Alternatively, you could use numpy like:

import numpy as np
x = np.random.uniform(30.0, 40.0, 10000)

NB: The second option would give you an ndarray, which is normally fine, but if your program requires you to have a list instead, you can just do this instead:

import numpy as np
x = np.random.uniform(30.0, 40.0, 10000).tolist()
sbottingota
  • 533
  • 1
  • 3
  • 18