Integer Overflow

Skip Montanaro skip at pobox.com
Wed Nov 28 16:46:04 CET 2001


    Ursus>  def Lcprng(state):
    Ursus>    """Pass this a variable containing the seed. Don't forget to
    Ursus>        update the seed with the returned value each time this
    Ursus>       function is called."""
    Ursus>    return int((29L*state+13L) & 0x0FFFFFFFL)

    Ursus> .......Calling Program......
    Ursus>  RanNum = 987654321 # Initialize Random Number Seed

    Ursus> ............................................

    Ursus>  RanNum = Lcprng(RanNum) # Keep updating seed with value

That works, however, it requires the caller to understand the mechanism
involved in updating the RNG's state.  With the one-element list version,
you (the RNG implementer) can stuff as much in the state as you like.  The
user can pretend it's opaque.

-- 
Skip Montanaro (skip at pobox.com - http://www.mojam.com/)




More information about the Python-list mailing list