0

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]

Esalah
  • 27
  • 1
  • 5
  • `random.random()/10000`? – timgeb Dec 03 '21 at 08:50
  • 1
    Does this answer your question? [How to get a random number between a float range?](https://stackoverflow.com/questions/6088077/how-to-get-a-random-number-between-a-float-range) – Mark Dickinson Dec 03 '21 at 12:27
  • 2
    `np.random.random` docs specify only one argument, the `size`, number of returned values. Range [0,1) is fixed. When getting errors like this, your **first** stop should be the function documentation. If it still isn't clear, then ask us :) – hpaulj Dec 03 '21 at 17:16

3 Answers3

2

you can use random.uniform like this

import random

print(random.uniform(0, 0.0001))
Mark Dickinson
  • 29,088
  • 9
  • 83
  • 120
2

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))
Mark Dickinson
  • 29,088
  • 9
  • 83
  • 120
iamniki
  • 553
  • 3
  • 11
1

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
Mark Dickinson
  • 29,088
  • 9
  • 83
  • 120
ahammond
  • 31
  • 6