469,356 Members | 2,021 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

random number generator

How to generate a random number in Python. Is there any build in
function I can call?

Thanks

Nov 3 '05 #1
3 1663
> How to generate a random number in Python. Is there any build in
function I can call?

import random
help(random)


also see:

http://docs.python.org/lib/module-random.html

</F>

Nov 3 '05 #2
import random
print random.randint(1,20)

#prints random integer from 1 to 20

Nov 4 '05 #3
Fredrik Lundh wrote:
How to generate a random number in Python. Is there any build in
function I can call?


>>> import random
>>> help(random)
If you need crypto-quality randomness:
import os
help(os.urandom)

--
--Bryan
Nov 4 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Brandon Michael Moore | last post: by
10 posts views Thread by Sonoman | last post: by
3 posts views Thread by Joe | last post: by
70 posts views Thread by Ben Pfaff | last post: by
5 posts views Thread by Peteroid | last post: by
104 posts views Thread by fieldfallow | last post: by
12 posts views Thread by Jim Michaels | last post: by
13 posts views Thread by porterboy76 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.