UserManual

bigrandom

The module provides random number generator for long integer.

historical note

The module was written for replacement of the Python standard module random, because in the era of Python 2.2 (prehistorical period of NZMATH) the random module raises OverflowError for long integer arguments for the randrange function, which is the only function having a use case in NZMATH.

After the creation of Python 2.3, it was theoretically possible to use random.randrange. Use of it is, however, not considered, since there is the bigrandom module. It is lucky for us and users. In fall of 2006, we found a bug in random.randrange and reported it (see issue tracker); the random.randrange accepts long integers but returns unreliable result for truly big integers. The bug was fixed for Python 2.5.1. You can, therefore, use random.randrange instead of bigrandom.randrange for Python 2.5.1 or higher.

Function

randrange(start [,stop[, step]])

returns a big random integer. You may set the parameters start, stop, (this means the interval [start, stop)) and step, the increment. For example:

>>> randrange(4,10000,3) 
9919L 

Or you can ignore the last two arguments. For example:

>>> randrange(4) 
3L

map_choice(mapping, upperbound)

Return a choice from a set given as the image of the mapping from natural numbers (more precisely range(upperbound)). In other words, it is equivalent to random.choice([mapping(i) for i in range(upperboud) if mapping(i) != None]) if upperbound is small enough for the list size limit.

The mapping can be a partial function, i.e. it may return None for some input. However, if the resulting set is empty, it will end up with an infinite loop.
(new in 0.90.0)