Re: I have a question.
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: I have a question.

From: Jeremy Jones <zanesdad@bellsouth.net>
Date: Thu Jun 30 2005 - 17:55:21 CEST

Nathan Pinno wrote:

> Hi all,
>
> Does Python have a random function? If so, can you show me an example
>using it?
>
> Thanks,
> Nathan Pinno
> http://www.npinnowebsite.ca/
>
>
>
>
>
Take your pick:

In [5]: import random

In [6]: random.choice(range(10))
Out[6]: 2

In [7]: random.choice(range(10))
Out[7]: 7

In [8]: random.choice(range(10))
Out[8]: 8

In [9]: random.choice(range(10))
Out[9]: 8

In [14]: random.random()
Out[14]: 0.56386154889489271

In [15]: random.random()
Out[15]: 0.47322827346926843

In [16]: random.random()
Out[16]: 0.39921336622176518

In [17]: random.random()
Out[17]: 0.65521407248459007

In [18]: random.random()
Out[18]: 0.74525381787627598
In [20]: r = range(10)

In [21]: random.shuffle(r)

In [22]: r
Out[22]: [6, 4, 9, 7, 2, 0, 8, 3, 5, 1]

Jeremy Jones
Received on Thu Sep 29 16:40:12 2005