diff options
| author | Lex Neva <github.com@lexneva.name> | 2023-01-17 21:44:23 -0500 |
|---|---|---|
| committer | Lex Neva <github.com@lexneva.name> | 2023-02-20 15:27:55 -0500 |
| commit | 847e133f97d570e2967dfa7dcfc16a212dc2bbbc (patch) | |
| tree | df2fb20547bea95ad437155a1fac91290a9d07f3 /lib/utils/list.py | |
| parent | e2965e78f03fb41c9a02c92ef120caf038b837ae (diff) | |
meander fill: more work
Diffstat (limited to 'lib/utils/list.py')
| -rw-r--r-- | lib/utils/list.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/utils/list.py b/lib/utils/list.py index 2bfe2cd7..efa3969e 100644 --- a/lib/utils/list.py +++ b/lib/utils/list.py @@ -1,8 +1,16 @@ -from random import randrange +import random -def poprandom(sequence): - index = randrange(len(sequence)) +def _uniform_rng(): + while True: + yield random.uniform(0, 1) + + +_rng = _uniform_rng() + + +def poprandom(sequence, rng=_rng): + index = int(round(next(rng) * (len(sequence) - 1))) item = sequence[index] # It's O(1) to pop the last item, and O(n) to pop any other item. So we'll |
