parameters: (bits, mod=None)
return_statement: return rand
docstring: Returns a random byte string of size `bits`/8 bytes.
  
      Args:
          bits (int): The number of bits the random string should have.
          mod (:obj:`ctypes.c_void_p`, optional): A pointer to a BN instance
      Returns:
          A byte strings of length `bits`/8 or None if an error occured
          If mod is set the random byte string will have a value < mod
docstring_summary: Returns a random byte string of size `bits`/8 bytes.
docstring_tokens: Returns a random byte string of size bits / 8 bytes .
function: def get_random(bits, mod=None):
      """
      Returns a random byte string of size `bits`/8 bytes.
  
      Args:
          bits (int): The number of bits the random string should have.
          mod (:obj:`ctypes.c_void_p`, optional): A pointer to a BN instance
      Returns:
          A byte strings of length `bits`/8 or None if an error occured
          If mod is set the random byte string will have a value < mod
      """
      ctx = _ssl.BN_CTX_new()
      _ssl.BN_CTX_start(ctx)
      r = _ssl.BN_CTX_get(ctx)
      ret = _ssl.BN_CTX_get(ctx)
  
      if mod:
          if _ssl.BN_rand_range(r, mod) == 0:
              logging.debug("get_random: failed to generate random number")
              return None
  
          while _ssl.BN_gcd(ret, r, mod, ctx) != 1:
              logging.debug("R is not a relative prime")
              if _ssl.BN_rand_range(r, mod) == 0:
                  logging.debug("get_random: failed to generate random number")
                  return None
  
      else:
          if _ssl.BN_rand(r, bits, 0, 1) == 0:
              logging.debug("get_random: failed to generate random number")
              return None
  
      rand = BNToBin(r, bits//8)
  
      _ssl.BN_free(r)
      _ssl.BN_free(ret)
      _ssl.BN_CTX_end(ctx)
      _ssl.BN_CTX_free(ctx)
  
      return rand
function_tokens: def get_random ( bits , mod = None ) : ctx = _ssl . BN_CTX_new ( ) _ssl . BN_CTX_start ( ctx ) r = _ssl . BN_CTX_get ( ctx ) ret = _ssl . BN_CTX_get ( ctx ) if mod : if _ssl . BN_rand_range ( r , mod ) == 0 : logging . debug ( "get_random: failed to generate random number" ) return None while _ssl . BN_gcd ( ret , r , mod , ctx ) != 1 : logging . debug ( "R is not a relative prime" ) if _ssl . BN_rand_range ( r , mod ) == 0 : logging . debug ( "get_random: failed to generate random number" ) return None else : if _ssl . BN_rand ( r , bits , 0 , 1 ) == 0 : logging . debug ( "get_random: failed to generate random number" ) return None rand = BNToBin ( r , bits // 8 ) _ssl . BN_free ( r ) _ssl . BN_free ( ret ) _ssl . BN_CTX_end ( ctx ) _ssl . BN_CTX_free ( ctx ) return rand