ó
’Ì0Ic           @   sÅ   d  Z  d d l Z d „  Z d „  Z d d d „  ƒ  YZ d d d „  ƒ  YZ e d	 k rÁ e ƒ  Z x% e d
 d ƒ D] Z	 e j
 d ƒ GHqo Wd d d d d d d g Z x e D] Z e e ƒ GHq© Wn  d S(   s±   handles true random numbers supplied from the the web server of fourmilab. Based on atmospheric noise.  The motivation is to support biosimulations that rely on random numbers.
iÿÿÿÿNc         C   s)   d d  l  } | j d t ƒ t |  d ƒ S(   Niÿÿÿÿs~   The function Bio.HotRand.hex_convert is deprecated. Instead of Bio.HotRand.hex_convert(text), please use int(text, 16) insteadi   (   t   warningst   warnt   DeprecationWarningt   int(   t   textR    (    (    s~   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/HotRand.pyt   hex_convert   s    c         C   sN   d } t  |  ƒ } x5 t d | ƒ D]$ } | d } | t |  | ƒ } q" W| S(   Ni    i   (   t   lent   ranget   ord(   R   t   valt   numbytest   i(    (    s~   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/HotRand.pyt   byte_concat   s    
t   HotCachec           B   s&   e  Z d  „  Z d „  Z d d „ Z RS(   c         C   s.   d |  _  i d d 6d d 6|  _ |  j ƒ  d  S(   Ns'   http://www.random.org/cgi-bin/randbyte?i€   t   nbytest   ht   fmt(   t   urlt   queryt   fill_hot_cache(   t   self(    (    s~   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/HotRand.pyt   __init__   s    	c         C   sE   |  j  t j |  j ƒ } t j | ƒ } | j ƒ  |  _ | j ƒ  d  S(   N(   R   t   urllibt	   urlencodeR   t   urlopent   readt	   hot_cachet   close(   R   R   t   fh(    (    s~   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/HotRand.pyR   "   s    i   c         C   s„   |  j  } | d } t | ƒ | d k rA d t | ƒ GHt ‚ n  | d k rc |  j ƒ  |  j  } n  | |  } | | |  _  t | ƒ S(   Ni   i    s   len_cache is %dt    (   R   R   t
   ValueErrorR   R   (   R   t
   num_digitst   cacheR
   t	   hexdigits(    (    s~   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/HotRand.pyt   next_num(   s    	
	

(   t   __name__t
   __module__R   R   R"   (    (    (    s~   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/HotRand.pyR      s   		t	   HotRandomc           B   s   e  Z d  „  Z d d „ Z RS(   c         C   s   t  ƒ  |  _ d  S(   N(   R   R   (   R   (    (    s~   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/HotRand.pyR   9   s    i    c         C   s5   | | } |  j  j ƒ  } | | d ?} | | } | S(   Ni   (   R   R"   (   R   t   hight   lowt   spanR	   (    (    s~   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/HotRand.pyt   hot_rand<   s
    

(   R#   R$   R   R)   (    (    (    s~   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/HotRand.pyR%   7   s   	t   __main__i    i‚   i   t   0000t   abcdt   1234t   5555t   4321t   aaaat   ffff(    (    (   t   __doc__R   R   R   R   R%   R#   t
   hot_randomR   t   jR)   t   numst   num(    (    (    s~   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/HotRand.pyt   <module>   s   				