, /:
import random
a = range(1,50)
for i in xrange(6):
b = a[random.randint(0,len(a)-i)]
a.remove(b)
print b
For people who care about efficiency, here is the test bench for my solution and Chin's:
>>> random.sample(xrange(1,50), 6)
[26, 39, 36, 46, 37, 1]
Results:
>python -mtimeit -s'import try2'
[38, 7, 31, 24, 30, 32]
100000000 loops, best of 3: 0.0144 usec per loop
>python -mtimeit -s'import try1'
36
26
41
31
37
14
100000000 loops, best of 3: 0.0144 usec per loop
decided to be the same!
source
share