Last active
February 15, 2018 13:29
-
-
Save neoshrew/fa7eb272da5e96380fa1a626ef5635a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
_DEF = object() | |
def bogo_range(start, end=_DEF, step=1): | |
if end is _DEF: | |
end = start | |
start = 0 | |
if not isinstance(end, int): | |
raise TypeError( | |
"bogo_range() integer end argument expected, got {}".format( | |
type(start)) | |
if not isinstance(start, int): | |
raise TypeError( | |
"bogo_range() integer start argument expected, got {}".format( | |
type(start)) | |
if not isinstance(step, int): | |
raise TypeError( | |
"bogo_range() integer step argument expected, got {}".format( | |
type(start)) | |
if step == 0: | |
raise ValueError("bogo_range() step argument must not be zero") | |
results = set() | |
required_items = round(float(end - start) / step) | |
while len(results) < required_items: | |
val = random.random() | |
val *= required_items - 1 | |
val = round(val) | |
val = int(val) | |
val *= step | |
val += start | |
results.add(val) | |
return sorted(results, reverse=step<0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment