Randomize the iterable. Note: this evaluates the entire iterable to a sequence in memory
(iterable, seed=None)
| 1 | def irandomize(iterable, seed=None): |
| 2 | """ |
| 3 | Randomize the iterable. |
| 4 | |
| 5 | Note: this evaluates the entire iterable to a sequence in memory |
| 6 | """ |
| 7 | if seed is None: |
| 8 | from random import shuffle |
| 9 | else: |
| 10 | from random import Random |
| 11 | shuffle = Random(seed).shuffle |
| 12 | result = list(iterable) |
| 13 | shuffle(result) |
| 14 | return iter(result) |
| 15 | |
| 16 | if __name__ == "__main__": |
| 17 | print list(irandomize(range(10))) |
no test coverage detected