def fast_urandom16(urandom=[], locker=threading.RLock()):
 try:
  return urandom.pop()
 except IndexError:
  try:
   locker.acquire()
   ur = os.urandom((16 * 1024))
   urandom += [ur[i:(i + 16)] for i in xrange(16, (1024 * 16), 16)]
   return ur[0:16]
  finally:
   locker.release()

def fast_urandom16 ( urandom = [ ] , locker = threading . RLock ( ) ) : try : return urandom . pop ( ) except IndexError : try : locker . acquire ( ) ur = os . urandom ( ( 16 * 1024 ) ) urandom += [ ur [ i : ( i + 16 ) ] for i in xrange ( 16 , ( 1024 * 16 ) , 16 ) ] return ur [ 0 : 16 ] finally : locker . release ( )
this is 4x faster than calling os .