I have a method that needs to select a random float val from a range of between st and ed, but I only want one of the endpoints included. (Or, in other terms, (st, ed] or [st, ed).) My current solution is:
import random
val = None
st, ed = 0, 360
## In application, what I want is an angle, but I've made it generic as an example.
while not (st <= val < ed): # which of st or ed to reject is up to you.
val = random.uniform(st, ed)
...but is there a way (by argument or notation) to tell random.uniform (or a function like it) to include or exclude one endpoint or another? Perhaps NumPy has an answer?
I am aware that the odds of getting two equivalent values in a range of floats with thirteen places of precision, that spans more than (or exactly) one integer is basically nil, but I'd like to know if only to better understand the tools themselves.
Aucun commentaire:
Enregistrer un commentaire