Reputation: 561
I need to generate a number from 0 to 1 that include 1 but not include 0
The random.uniform(0,1)
function include 0 but not include 1
How is it possible to do that?
Upvotes: 2
Views: 288
Reputation: 3379
You could alternatively use:
import random as r
-r.uniform(-1, 0)
So in general:
# random number which excludes a but excludes b
import random as r
def my_uniform(a = 0, b = 1):
return -r.uniform(-b, -a)
Upvotes: 0
Reputation: 2328
Numpy’s uniform random generator generates values on a [a,b) interval where a is low and b is high.
Samples are uniformly distributed over the half-open interval [low, high) (includes low, but excludes high). In other words, any value within the given interval is equally likely to be drawn by uniform
Upvotes: 0