randomdotorg


random.org number generator interface module

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.

Download

https://pypi.python.org/packages/source/r/randomdotorg/randomdotorg-0.1.3a3.tar.gz

Installation

python setup.py install

Usage example

```

r = randomdotorg.RandomOrg('ExampleProgram') # Pass the name of your program 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(amount=3) # passing amount returns a list of random() calls [0.080465695508892002, 0.44239923585566199, 0.89425081132204098] print r.randrange(2, 33, 3, amount=3) # using amount 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('ExampleProgram') ```

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('SeedGrabber').get_seed())

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

Project Information

Labels:
random Python