By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,763 Members | 1,406 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,763 IT Pros & Developers. It's quick & easy.

random number generator

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

Thanks

Nov 3 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
> 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

P: n/a
import random
print random.randint(1,20)

#prints random integer from 1 to 20

Nov 4 '05 #3

P: n/a
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.