For example, I wanted the numbers generated by a randint
to be 350
, 400
, 450
and 500
. Would you be able to do that?
For example, I wanted the numbers generated by a randint
to be 350
, 400
, 450
and 500
. Would you be able to do that?
From what I understand, what you want to do is generate numbers within a range
and set the step . In this case you can use random.randrange()
, which receives the start, end, and step parameters. Something like:
import random
valor = random.randrange(350,501,50)
Please be clear on the following questions, this helps to help you:)
Reference: random documentation
To do what you want, you could use random.sample
, for example:
random.sample([350, 400, 450, 500], 1)
Where the first parameter is the possible values and the second parameter how many values do you want to return.
Will return:
[400]
Source: link