My favorites | Sign in
Project Logo
                
Code license: GNU General Public License v3
Labels: random
Show all Featured wiki pages:
Differences
Feeds:
People details
Project owners:
  nosklo

randomdotorg.py is a python module to implement python's random number interface by fetching data from random.org, which is is a true random number service that generates randomness via atmospheric noise.

Usage example:

>>> r = randomdotorg.RandomOrg()
>>> print r.get_quota() # method to check bit quota
999171
>>> print r.randrange(2, 33, 3)
32
>>> L = ['duck', 'dog', 'cat', 'cow', 'gnu']
>>> print r.choice(L) # random element from L
duck
>>> print r.sample(L, 3) # 3 distinct random elements from the list
['gnu', 'duck', 'cat']
>>> r.shuffle(L) # L is now in random order
>>> print L
['gnu', 'cow', 'cat', 'dog', 'duck']
>>> print r.random(ammount=3) # passing ammount returns a list of random() calls
[0.080465695508892002, 0.44239923585566199, 0.89425081132204098]
>>> print r.randrange(2, 33, 3, ammount=3) # using `ammount` is more efficient.
[8, 14, 32]

Methods supported by the standard library random module are supported, except for save/load state and seeding, because those won't make sense for a true random number generator.

To use it as a drop-in replacement for the random module:

# import random    # remove this line
from randomdotorg import RandomDotOrg
random = RandomDotOrg()

or if you don't need really strong random data, just seed random with random.org seed:

import random
from randomdotorg import RandomDotOrg
random.seed(RandomDotOrg().get_seed()) 

There are some featured Differences from random module you might want to check.









Hosted by Google Code