Could anyone help walk me through the process of generating random numbers in Python?
More specifically, I'm trying to generate random numbers from a specified range.
Could anyone help walk me through the process of generating random numbers in Python?
More specifically, I'm trying to generate random numbers from a specified range.
For further actions, you may consider blocking this person and/or reporting abuse
Muhammad Ali -
Hiredeveloper -
11 -
Dorian Sabitov -
Top comments (7)
@swizzard and @yechielk are right on here.
randint()
will return a number integer betweenrange_min
andrange_max
inclusive. So if you callrandint(1,10)
you will get a random integer equal to 1, 2, 3, ..., 9, 10.The
random
library has a number of useful functions in it for dealing with random things. For example if you need a random element from a list, usechoice()
:Documentation is here: docs.python.org/3/library/random.html
Awesome thank you so much. Taking a look at that documentation now π
Will give you a number between 1 and 100
thanks Yechiel π
Hi. I wrote a Cheatsheet here which covers random strings, integers, floats and more.
michaelcurrin.github.io/dev-cheats...
Some comments may only be visible to logged-in visitors. Sign in to view all comments.