-1

I want to generate random ints from 4 specific numbers (1,2,5,10). I only want the output to be one of these. How?

Lili
  • 9
  • 2

2 Answers2

1

You can use the choice method:

random.choice([1, 2, 5 ,10])

Hope this helps

Juleaume
  • 83
  • 1
  • 8
1

You can use random.choice like so:

import random

nums = [1, 2, 5, 10]
print(random.choice(nums)) # prints either 1, 2, 5, or 10

You can view more at the documentation: https://docs.python.org/3/library/random.html#random.choice

Thornily
  • 533
  • 3
  • 15