2005-10-17 02:30:05

Thread-safe random number generation

We consider a physical source of entropy to be better than a simulated one, so we will try to use one (/dev/urandom on posix, for example). If a pseudo-random number generator is to be used, it should be seeded from the physical source, if possible, rather than the usual custom of seeding it from the system clock. Random number sources that are not known to be thread-safe should be polled serially.

Copyright 2005 Fourthought, Inc. (USA). Detailed license and copyright information: http://4suite.org/COPYRIGHT Project home, documentation, distributions: http://4suite.org/

Returns numBytes random bytes from the best RNG available

Returns a random float, n, where 0 <= n < 1

['dev_rand_fd', 'pseudo_rng', 'GetRandomBytes', 'Random']
9

A lock object is a synchronization primitive. To create a lock, call the PyThread_allocate_lock() function. Methods are:

acquire() -- lock the lock, possibly blocking until it can be obtained release() -- unlock of the lock locked() -- test whether the lock is currently locked

A lock is not owned by the thread that locked it; another thread may unlock it. A thread attempting to lock a lock that it has already locked will block until another thread unlocks it. Deadlocks may ensue.
<thread.lock object>

Random number generator base class used by bound module functions.

Used to instantiate instances of Random to get generators that don't share state. Especially useful for multi-threaded programs, creating a different instance of Random for each thread, and using the jumpahead() method to ensure that the generated sequences seen by each thread don't overlap.

Class Random can also be subclassed if you want to use a different basic generator of your own devising: in that case, override the following methods: random(), seed(), getstate(), setstate() and jumpahead(). Optionally, implement a getrandombits() method so that randrange() can cover arbitrarily large ranges.
<random.Random object>
False