Skip to content

Instantly share code, notes, and snippets.

@hlecuanda
Created December 20, 2022 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hlecuanda/24422b3587f4e5599d2122d22dcd1eba to your computer and use it in GitHub Desktop.
Save hlecuanda/24422b3587f4e5599d2122d22dcd1eba to your computer and use it in GitHub Desktop.
Get a random integer
#!/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