def sample_uniform(domain, rng):
  """Sample a value uniformly from a domain.

  Args:
    domain: An `IntInterval`, `RealInterval`, or `Discrete` domain.
    rng: A `random.Random` object; defaults to the `random` module.

  Raises:
    TypeError: If `domain` is not a known kind of domain.
    IndexError: If the domain is empty.
  """
  if isinstance(domain, hp.IntInterval):
    return rng.randint(domain.min_value, domain.max_value)
  elif isinstance(domain, hp.RealInterval):
    return rng.uniform(domain.min_value, domain.max_value)
  elif isinstance(domain, hp.Discrete):
    return rng.choice(domain.values)
  else:
    raise TypeError("unknown domain type: %r" % (domain,))
def sample_uniform ( domain , rng ) : if isinstance ( domain , hp . IntInterval ) : return rng . randint ( domain . min_value , domain . max_value ) elif isinstance ( domain , hp . RealInterval ) : return rng . uniform ( domain . min_value , domain . max_value ) elif isinstance ( domain , hp . Discrete ) : return rng . choice ( domain . values ) else : raise TypeError ( "unknown domain type: %r" % ( domain , ) )
Sample a value uniformly from a domain.

  Args:
    domain: An `IntInterval`, `RealInterval`, or `Discrete` domain.
    rng: A `random.Random` object; defaults to the `random` module.

  Raises:
    TypeError: If `domain` is not a known kind of domain.
    IndexError: If the domain is empty.