random picks from a list

Gerrit Holl gerrit at nl.linux.org
Fri Jun 13 00:19:15 CEST 2003


Rogue9 wrote:
> I´m working on a program for lottery analysing and need to generate
> random numbers from a filtered list of numbers i.e. I have reduced the
> likely ¨winning¨ numbers to a smaller pool and have them in a list. How
> do i use the random funtion in Python to pick random numbers from this
> list?Is this the use of the seq argument in the random function?
> The documentation does not cover the use of all the arguments available
> for this function and my attempts to use if have been a failure.

Just two more cents here:
As of Python 2.3, you can do random.sample(seq, k):

 40 >>> seq
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
 41 >>> random.sample(seq, 10)
['I', 'D', 'u', 'O', 'W', 'H', 'A', 'a', 's', 't']

yours,
Gerrit.

-- 
175. If a State slave or the slave of a freed man marry the daughter of
a free man, and children are born, the master of the slave shall have no
right to enslave the children of the free.
        -- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
	http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
	http://www.sp.nl/





More information about the Python-list mailing list