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
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
random.sample
is another that can be usedTry this:
Return a random integer N such that a <= N <= b.
Docs: https://docs.python.org/3.1/library/random.html#random.randint
This generates 10 pseudorandom integers in range 0 to 9 inclusive.
if you want to use numpy then use the following:
For the example that you have given (integers starting from 0 and going until 9), the cleanest solution is as follows: