[Subversion] / PEAK / src / peak / util / random.py  

Diff of /PEAK/src/peak/util/random.py

Parent Directory | Revision Log

version 444, Thu Jul 4 15:28:35 2002 UTC version 2056, Wed Apr 27 06:30:39 2005 UTC
Line 1 
Line 1 
 """  """Obtain bytes of random data with varying degrees of quality,
 Obtain bytes of random data with varying degrees of quality, using  using OS facilities for high-quality entropy if available."""
 OS facilities for high-quality entropy if available.  
 """  
   
 __all__ = ['randbytes', 'rand16']  __all__ = ['randbytes', 'rand16']
   
   
 import sys, os, time  import sys, os, time
 from whrandom import random, seed  random = __import__('random',{}).random   # from _.random import random
 seeded = 0  seeded = 0
   
 try:  try:
Line 22 
Line 20 
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
 lasthash = seedhash = ''  lasthash = seedhash = ''
   
 def prng_some():  def prng_some():
Line 56 
Line 73 
 prng_some()  prng_some()
   
   
   
   
   
   
   
   
   
 def prng(nbytes):  def prng(nbytes):
     """      """
     A PRNG that hopefully is better than just using whrandom.      A PRNG that hopefully is better than just using random.
     Don't trust this for crypto, though!      Don't trust this for crypto, though!
     """      """
   
Line 93 
Line 117 
         return None          return None
   
   
   
   
   
   
 funcs = {  funcs = {
     #(prng, wait) : function      #(prng, wait) : function
   
Line 120 
Line 148 
 # through python, it should be added here. XXX  # through python, it should be added here. XXX
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
 def randbytes(nbytes, prng=1, wait=0):  def randbytes(nbytes, prng=1, wait=0):
     """      """
     Get nbytes number of bytes of randomness if possible.      Get nbytes number of bytes of randomness if possible.
Line 143 
Line 185 
   
     s = randbytes(2, prng, wait)      s = randbytes(2, prng, wait)
     return (ord(s[0]) << 8) | ord(s[1])      return (ord(s[0]) << 8) | ord(s[1])
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   


Generate output suitable for use with a patch program
Legend:
Removed from v.444  
changed lines
  Added in v.2056

cvs-admin@eby-sarna.com

Powered by ViewCVS 1.0-dev

ViewCVS and CVS Help