Is it possible to manipulate the numbers of a randint?

Asked

Viewed 71 times

-1

For example, I wanted the numbers generated by a randint were 350, 400, 450 and 500. You could do that?

  • It wasn’t clear. Do you want something that randomly draws defined values? It didn’t make much sense.

  • kkkk really got bugged, it’s like this if I ask him to give an a = randint(350, 500) he’ll draw from 350 to 500 type 350 351 352 I just wanted these values 300 350 400 ...

  • it’s a little clearer now?

2 answers

5


From what I understand, what you want to do is generate numbers within a range and define the footstep. In that case you can use the random.randrange(), which takes by parameter the beginning, end, and step. Something like:

import random
valor = random.randrange(350,501,50)

Please be clearer in the next questions, it helps to help you :)

Reference: documentation

  • worth I got to do what I wanted

2

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 you want to return.

Will return:

[400]

Source: https://docs.python.org/3.1/library/random.html

  • worth I got to do what I wanted

Browser other questions tagged

You are not signed in. Login or sign up in order to post.