code: def sanitize_seed(seed, salt=None, name=None):
      """Map various PRNG seed flavors to a seed `Tensor`.
  
      This function implements TFP's standard PRNG seeding semantics.
      See https://github.com/tensorflow/probability/blob/main/PRNGS.md
      for details.
  
      Operationally, `sanitize_seed` maps any seed flavor to a
      "stateless-compatible" seed.  Under TensorFlow and NumPy this means:
      - If the `seed` argument is an `int` or `None`, we use `tf.random.uniform`
        to _statefully_ draw a pair of unbounded `int32`s and wrap them into a
        Tensor.
      - If the `seed` argument is a stateless-compatible seed already, we
        just cast it to an `int32[2]` Tensor.
  
      Under JAX, this function only accepts outputs from `jax.random.PRNGKey`, being
      a no-op except for the salting behavior described below.
  
      This, any function that accepts a `seed` argument can be written in
      stateless-seed style internally, and acquires TFP's
      seed-type-directed stateless/stateful switching behavior by just
      running the input seed through `sanitize_seed` on entry.
  
      The `sanitize_seed` function also allows salting the seed: if a user
      accidentally passes the same stateful seed to two different calls to
      `sanitize_seed` with different salts, they will get independent
      randomness.  We may micro-optimize by removing salting from
      `sanitize_seed` of already-stateless seeds in the future, as using a
      stateless seed already requires seed uniqueness discipline.
  
      Args:
        seed: An `int32[2]` Tensor or a Python list or tuple of 2 `ints`,
          which will be treated as stateless seeds; or a Python `int` or
          `None`, which will be treated as stateful seeds.
        salt: An optional Python string.
        name: An optional Python string, name to add to TF ops created by
          this function.
  
      Returns:
        seed: An `int32[2]` Tensor suitable for use as a stateless PRNG
          seed.
  
      """
      if callable(seed):  # e.g. SeedStream.
          seed = seed()
      if salt is not None and not isinstance(salt, str):
          raise TypeError(
              "`salt` must be a python `str`, got {}".format(repr(salt))
          )
      with tf.name_scope(name or "sanitize_seed"):
          if is_stateful_seed(seed):
              if JAX_MODE:
                  raise ValueError(
                      "TFP-on-JAX requires a `jax.random.PRNGKey` `seed` arg."
                  )
              elif (
                  tf.distribute.get_replica_context() is not None
                  and tf.distribute.get_replica_context().num_replicas_in_sync
                  > 1
              ):
                  warnings.warn(
                      "Using stateful random seeds in replicated context can yield "
                      "unreproducible results. For more details, see "
                      "https://github.com/tensorflow/probability/blob/main/PRNGS.md"
                  )
  
              # TODO(b/147874898): Deprecate `int` seeds, migrate ints to stateless?
              if salt is not None:
                  # Prefer to incorporate salt as a constant.
                  if seed is not None:
                      seed = int(
                          hashlib.sha512(
                              str((seed, salt)).encode("utf-8")
                          ).hexdigest(),
                          16,
                      ) % (2**31 - 1)
                  salt = None
              # Convert "stateful-indicating" `int`/`None` seed to stateless Tensor seed
              # by way of a stateful sampler.
              seed = tf.random.uniform(
                  [2],
                  seed=seed,
                  minval=np.iinfo(SEED_DTYPE).min,
                  maxval=np.iinfo(SEED_DTYPE).max,
                  dtype=SEED_DTYPE,
                  name="seed",
              )
  
          # TODO(b/223267515): In JAX mode, raise a user-friendly error if seed is
          # not a PRNGKey.
  
          # TODO(b/159209541): Consider ignoring salts for stateless seeds, for
          # performance and because using stateless seeds already requires the
          # discipline of splitting.
  
          if salt is not None:
              salt = int(
                  hashlib.sha512(str(salt).encode("utf-8")).hexdigest(),
                  16,
              )
              seed = fold_in(seed, salt)
  
          if JAX_MODE:
              # Seed must be a jax.PRNGKey -- so just return it.
              return seed
          return tf.convert_to_tensor(
              seed, dtype=SEED_DTYPE, name="seed"
          )
  
file_path: probability/tensorflow_probability/python/internal/samplers.py
imports: import hashlib
  import warnings
  import numpy
  import six
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import prefer_static
label_desc: Use image node_id 3 for calling a global function with example usage: sanitize_seed(seed, salt, name) and returns: tf, seed