My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Differences  
new methods and new parameters in comparision to `random.Random` class
Featured, Phase-Implementation
Updated Dec 3, 2008 by nosklo@gmail.com
>>> r = randomdotorg.RandomDotOrg()

Parameters

The .random(), .choice() and .randrange() methods take an extra ammount parameter which if passed, makes the respective function return a list of ammount results instead of a single one, but internally it will efficiently fetch multiple numbers at a single request, so it is preferred over calling the method many times.

>>> print r.random(ammount=2)
[0.23158234863091201, 0.399227382586543]
>>> print r.randrange(1, 40, 2, ammount=4)
[35, 23, 21, 23]
>>> print r.choice(['some', 'elements', 'to', 'choose'], ammount=7)
['choose', 'choose', 'some', 'elements', 'to', 'elements', 'some']

New methods

This section lists the new methods added to RandomDotOrg instance that aren't on random.Random:

get_quota()

Returns available bit quota from random.org:

>>> print r.get_quota():
973765

get_seed()

Returns a really random seed suitable to use with random module. It will be a 20 digit long integer.

>>> seed = r.get_seed()
>>> print seed
93879958772852339020
>>> import random
>>> random.seed(seed)

write_random_bytes(fileobj, num_bytes=256)

Writes num_bytes bytes to the file object fileobj. Use it to feed /dev/random:

>>> r.write_random_bytes(open('/dev/random', 'a'))

Sign in to add a comment
Powered by Google Project Hosting