random picks from a list

Daniel Fackrell newsgroups.NOSPAM at dfackrell.mailshell.com
Thu Jun 12 22:06:54 CEST 2003


Rogue9 wrote:
> Hi All,
> 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. Guidance would be very much welcome Pythonistas,
> Thanks
> Lol McBride

Is random.choice() what you seek?

>>> import random
>>> random.choice([1, 5, 3, 4, 756])
4
>>> random.choice([1, 5, 3, 4, 756])
1
>>> random.choice([1, 5, 3, 4, 756])
756
>>> random.choice([1, 5, 3, 4, 756])
756
>>> random.choice([1, 5, 3, 4, 756])
5
>>>

--
Daniel Fackrell (newsgroups.NOSPAM at dfackrell.mailshell.com)
When we attempt the impossible, we can experience true growth.






More information about the Python-list mailing list