1#This will return a list of 50 numbers selected from the range 0 to 999, without duplicates.
2import random
3random.sample(range(1000), 50)
1import random
2
3def random_sample(count, start, stop, step=1):
4 def gen_random():
5 while True:
6 yield random.randrange(start, stop, step)
7
8 def gen_n_unique(source, n):
9 seen = set()
10 seenadd = seen.add
11 for i in (i for i in source() if i not in seen and not seenadd(i)):
12 yield i
13 if len(seen) == n:
14 break
15
16 return [i for i in gen_n_unique(gen_random,
17 min(count, int(abs(stop - start) / abs(step))))]
18
1python -c "import random; print(sorted(set([random.randint(6,49) for i in range(7)]))[:6])"
2