code: def sample_bounded_spec(spec, rng):
      """Samples the given bounded spec.
  
      Args:
        spec: A BoundedSpec to sample.
        rng: A numpy RandomState to use for the sampling.
  
      Returns:
        An np.array sample of the requested spec.
      """
      tf_dtype = tf.as_dtype(spec.dtype)
      low = spec.minimum
      high = spec.maximum
  
      if tf_dtype.is_floating:
          if spec.dtype == np.float64 and np.any(np.isinf(high - low)):
              # The min-max interval cannot be represented by the np.float64. This is a
              # problem only for np.float64, np.float32 works as expected.
              # Spec bounds are set to read only so we can't use argumented assignment.
              low = low / 2
              high = high / 2
          return rng.uniform(
              low,
              high,
              size=spec.shape,
          ).astype(spec.dtype)
  
      else:
          if spec.dtype == np.int64 and np.any(high - low < 0):
              # The min-max interval cannot be represented by the tf_dtype. This is a
              # problem only for int64.
              low = low / 2
              high = high / 2
  
          if np.any(high < tf_dtype.max):
              high = np.where(high < tf_dtype.max, high + 1, high)
          elif spec.dtype != np.int64 or spec.dtype != np.uint64:
              # We can still +1 the high if we cast it to the larger dtype.
              high = high.astype(np.int64) + 1
  
          if low.size == 1 and high.size == 1:
              return rng.randint(
                  low,
                  high,
                  size=spec.shape,
                  dtype=spec.dtype,
              )
          else:
              return np.reshape(
                  np.array(
                      [
                          rng.randint(
                              low, high, size=1, dtype=spec.dtype
                          )
                          for low, high in zip(
                              low.flatten(), high.flatten()
                          )
                      ]
                  ),
                  spec.shape,
              )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numbers
  import gin
  import numpy
  import tensorflow
label_desc: Use image node_id 1 for calling a global function with example usage: sample_bounded_spec(spec, rng) and returns: rng, rng, np