Created
December 20, 2022 18:45
-
-
Save hlecuanda/24422b3587f4e5599d2122d22dcd1eba to your computer and use it in GitHub Desktop.
Get a random integer
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
#!/usr/bin/env python3 | |
""" Prints a random integer to stdout | |
Usage: | |
random-int [NUMBER] | |
where NUMBER is any real number in the valid range for | |
int() or real() in python | |
Returns: | |
A random number in the range [0..NUMBER] | |
""" | |
import sys | |
import random | |
import math | |
random.seed() | |
def randint(a=100): | |
return math.floor(random.random() * a) | |
if __name__ == '__main__': | |
if len(sys.argv) > 1: | |
print(randint(int(sys.argv[1]))) | |
else: | |
print(randint()) | |
sys.exit(0) | |
# d(-_-;)bm hlo.mx/random-int 1671560396 | |
# vim: set ts=4 sw=4 tw=80 et : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment