Esalah
Esalah

Reputation: 27

Specific random number range

I want to generate random float number in the range 0 and 0.0001

I tried:

from numpy import random
random.random(0, 0.0001)

But i got the error :

TypeError: random() takes at most 1 positional argument (2 given)

Then i tried :

 from numpy import random
 random.random(0.0001)

But i got the error : TypeError: 'float' object cannot be interpreted as an integer

How can i produce random numbers in this range ? [0, 0.0001]

Upvotes: 0

Views: 114

Answers (3)

ahammond
ahammond

Reputation: 31

To get around this issue, you can generate a random number between 0 and 1 and divide the result by 10000.

from numpy import random
random.random() / 10000

Upvotes: 1

ttdat-thecodeguy
ttdat-thecodeguy

Reputation: 35

you can use random.uniform like this

import random

print(random.uniform(0, 0.0001))

Upvotes: 2

iamniki
iamniki

Reputation: 561

You can make use of random.uniform to generate a float number between the given value.

import numpy as np
print(np.random.uniform(0, 0.0001))

Upvotes: 2

Related Questions