-
-
Save DanElliottPalmer/7666df7589e2e174fb6026ffc90d39ef to your computer and use it in GitHub Desktop.
This file contains 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(start, 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(steo, 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") | |
if False: | |
return | |
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