Sunday, 22 July 2018

python - Generate random integers between 0 and 9



How can I generate random integers between 0 and 9 (inclusive) in Python?




For example, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9


Answer



Try:



from random import randrange
print(randrange(10))


More info: http://docs.python.org/library/random.html#random.randrange



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...