tips for this exercise?
Paul Rubin
http
Tue Mar 28 18:18:03 EST 2006
Steven D'Aprano <steve at REMOVETHIScyber.com.au> writes:
> Generally, lottery numbers are selected from a range, e.g. one to forty.
> So rather than passing a global list, just pass the maximum number:
>
> def getNumbers(maxn=40):
> L = range(1, maxn+1)
> random.shuffle(L)
> return L[0:5]
Why is everyone using shuffle?
Python 2.3.4 (#1, Feb 2 2005, 12:11:53)
[GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
>>> random.sample(xrange(1,41), 5)
[24, 15, 9, 39, 19]
More information about the Python-list
mailing list