code: def sample_bounded_spec(spec, seed=None, outer_dims=None):
      """Samples uniformily the given bounded spec.
  
      Args:
        spec: A BoundedSpec to sample.
        seed: A seed used for sampling ops
        outer_dims: An optional `Tensor` specifying outer dimensions to add to the
          spec shape before sampling.
  
      Returns:
        A Tensor sample of the requested spec.
      """
      minval = spec.minimum
      maxval = spec.maximum
      dtype = tf.as_dtype(spec.dtype)
  
      # To sample uint8 we will use int32 and cast later. This is needed for two
      # reasons:
      #  - tf.random_uniform does not currently support uint8
      #  - if you want to sample [0, 255] range, there's no way to do this since
      #    tf.random_uniform has exclusive upper bound and 255 + 1 would overflow.
      is_uint8 = dtype == tf.uint8
      sampling_dtype = tf.int32 if is_uint8 else dtype
  
      if dtype in [tf.float64, tf.float32]:
          # Avoid under/over-flow as random_uniform can't sample over the full range
          # for these types.
          minval = np.maximum(dtype.min / 8, minval)
          maxval = np.minimum(dtype.max / 8, maxval)
  
      if outer_dims is None:
          outer_dims = tf.constant([], dtype=tf.int32)
      else:
          outer_dims = tf.convert_to_tensor(outer_dims, dtype=tf.int32)
  
      def _unique_vals(vals):
          if vals.size > 0:
              if vals.ndim > 0:
                  return np.all(vals == vals[0])
          return True
  
      if (minval.ndim != 0 or maxval.ndim != 0) and not (
          _unique_vals(minval) and _unique_vals(maxval)
      ):
          # tf.random_uniform can only handle minval/maxval 0-d tensors.
          res = _random_uniform_int(
              shape=spec.shape,
              outer_dims=outer_dims,
              minval=minval,
              maxval=maxval,
              dtype=sampling_dtype,
              seed=seed,
          )
      else:
          minval = minval.item(0) if minval.ndim != 0 else minval
          maxval = maxval.item(0) if maxval.ndim != 0 else maxval
          # BoundedTensorSpec are bounds inclusive.
          # tf.random_uniform is upper bound exclusive, +1 to fix the sampling
          # behavior.
          # However +1 will cause overflow, in such cases we use the original maxval.
          if sampling_dtype.is_integer and maxval < sampling_dtype.max:
              maxval = maxval + 1
  
          shape = tf.convert_to_tensor(spec.shape, dtype=tf.int32)
          full_shape = tf.concat((outer_dims, shape), axis=0)
          res = tf.random.uniform(
              full_shape,
              minval=minval,
              maxval=maxval,
              dtype=sampling_dtype,
              seed=seed,
          )
  
      if is_uint8:
          res = tf.cast(res, dtype=dtype)
  
      return res
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  from typing import Union
  import numpy
  import tensorflow
  import tensorflow_probability
  from tf_agents.specs import array_spec
  from tf_agents.typing import types
  from google.protobuf import text_format
  from tensorflow.core.protobuf import struct_pb2
  from tensorflow.python.framework import tensor_spec
  from tensorflow.python.saved_model import nested_structure_coder
label_desc: Use image node_id 11 for calling a global function with example usage: sample_bounded_spec(spec, seed, outer_dims) and returns: res, True, np