code: def _old_tf_random_stateless_uniform(
      shape,
      seed,
      minval=0,
      maxval=None,
      dtype=dtypes.float32,
      name=None,
      layout=None,
  ):
      """DTensor stateless uniform implementation that takes an layout."""
      dtype = dtypes.as_dtype(dtype)
      accepted_dtypes = (
          dtypes.float16,
          dtypes.bfloat16,
          dtypes.float32,
          dtypes.float64,
          dtypes.int32,
          dtypes.int64,
          dtypes.uint32,
          dtypes.uint64,
      )
      if dtype not in accepted_dtypes:
          raise ValueError(
              f"Argument `dtype` got invalid value {dtype}. Accepted dtypes are "
              f"{accepted_dtypes}."
          )
      if dtype.is_integer:
          if (minval is None) != (maxval is None):
              raise ValueError(
                  f"For integer `dtype` argument {dtype}, argument `minval` and "
                  f"`maxval` must be both None or not None. Got `minval`={minval} and "
                  f"`maxval`={maxval}."
              )
          if minval is not None and dtype in (
              dtypes.uint32,
              dtypes.uint64,
          ):
              raise ValueError(
                  f"Argument `dtype` got invalid value {dtype} when argument `minval` "
                  "is not None. Please don't use unsigned integers in this case."
              )
  
      shape = shape_util.shape_tensor(shape)
      with ops.name_scope(
          name,
          "stateless_random_uniform",
          [shape, seed, minval, maxval],
      ) as name:
          seed = ops.convert_to_tensor(
              seed, dtype_hint=dtypes.int32, name="seed"
          )
  
          if dtype.is_integer and minval is None and maxval is None:
              result = api.call_with_layout(
                  gen_stateless_random_ops.stateless_random_uniform_full_int,
                  layout,
                  shape,
                  seed=seed,
                  dtype=dtype,
                  name=name,
              )
          else:
              if not dtype.is_integer and maxval is None:
                  maxval = 1
              val_range = ops.convert_to_tensor(
                  maxval - minval, dtype=dtype, name="range"
              )
              minval = ops.convert_to_tensor(
                  minval, dtype=dtype, name="min"
              )
              if dtype.is_integer:
                  result = api.call_with_layout(
                      gen_stateless_random_ops.stateless_random_uniform_int,
                      layout,
                      shape,
                      seed=seed,
                      minval=minval,
                      maxval=maxval,
                  )
              else:
                  rnd = api.call_with_layout(
                      gen_stateless_random_ops.stateless_random_uniform,
                      layout,
                      shape,
                      seed=seed,
                      dtype=dtype,
                  )
                  result = math_ops.add(
                      rnd * val_range, minval, name=name
                  )
          shape_util.maybe_set_static_shape(result, shape)
          return result
  
file_path: tensorflow-upstream/tensorflow/dtensor/python/d_random.py
imports: from tensorflow.dtensor.python import api
  from tensorflow.dtensor.python import layout
  from tensorflow.python.eager import context
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor_shape
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import gen_math_ops
  from tensorflow.python.ops import gen_stateless_random_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import shape_util
label_desc: Use image node_id 2 for calling a global function with example usage: _old_tf_random_stateless_uniform(shape, seed, minval, maxval, dtype, name, layout) and returns: result