0

So I have a program that randomly selects a certain amount of items from a list, but if a value is randomly selected I would like it to only print once, and make the program unable to print the same value twice. How do I do this?

import random
list = [25, 50, 75, 100]
big = int(raw_input("Big numbers: "))
y = big
b = 0
while b < y:
    j = random.choice(list)
    print j
    b += 1
Cooper
  • 45
  • 1
  • 6

1 Answers1

2

random.choice isn't the right method to use here. Use random.sample instead:

import random
mylist = [25, 50, 75, 100]
big = int(raw_input("Big numbers: "))
for num in random.sample(mylist, big):
    print num
TigerhawkT3
  • 48,464
  • 6
  • 60
  • 97