Skip to content

Commit

Permalink
adds random_float
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom O'Hara committed Nov 2, 2023
1 parent b781543 commit 3029c75
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions mezcla/misc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,20 @@ def random_int(min_value=None, max_value=None):
return result


def random_float(min_value=None, upper_bound=None):
"""Returns random float in range [min_value, upper_bound)
Note: defaults to [0, 1).
"""
if min_value is None:
min_value = 0
if upper_bound is None:
upper_bound = 1
result = (min_value + (random.random() * (upper_bound - min_value)))
debug.assertion(result < upper_bound)
debug.trace(6, f"random_float() => {result}")
return result


def time_function(func, *args, **kwargs):
"""Time invocation of FUNC, optionally supplied with ARGS and KWARGS"""
## EX: is_close(time_function(time.sleep, 5), 5000, epsilon=1)
Expand Down

0 comments on commit 3029c75

Please sign in to comment.