class_docstr: An interface for handling random state locally, currently based on a class
  variable `R`, which is an instance of `np.random.RandomState`.  This
  provides the flexibility of component-specific determinism without
  affecting the global states.  It is recommended to use this API with
  :py:class:`monai.data.DataLoader` for deterministic behaviour of the
  preprocessing pipelines. This API is not thread-safe. Additionally,
  deepcopying instance of this class often causes insufficient randomness as
  the random states will be duplicated.
class_docstr_tok: ["An","interface","for","handling","random","state","locally",",","currently","based","on","a","class","variable","`","R","`",",","which","is","an","instance","of","`","np.random.RandomState","`",".","This","provides","the","flexibility","of","component-specific","determinism","without","affecting","the","global","states",".","It","is","recommended","to","use","this","API","with",":","py",":","class",":","`","monai.data.DataLoader","`","for","deterministic","behaviour","of","the","preprocessing","pipelines",".","This","API","is","not","thread-safe",".","Additionally",",","deepcopying","instance","of","this","class","often","causes","insufficient","randomness","as","the","random","states","will","be","duplicated","."]
docstr: Set the random state locally, to control the randomness, the derived
  classes should use :py:attr:`self.R` instead of `np.random` to introduce random
  factors.
  
  Args:
      seed: set the random state with an integer seed.
      state: set the random state with a `np.random.RandomState` object.
  
  Raises:
      TypeError: When ``state`` is not an ``Optional[np.random.RandomState]``.
  
  Returns:
      a Randomizable instance.
code: def set_random_state(
      self,
      seed: int | None = None,
      state: np.random.RandomState | None = None,
  ) -> Randomizable:
      """
      Set the random state locally, to control the randomness, the derived
      classes should use :py:attr:`self.R` instead of `np.random` to introduce random
      factors.
  
      Args:
          seed: set the random state with an integer seed.
          state: set the random state with a `np.random.RandomState` object.
  
      Raises:
          TypeError: When ``state`` is not an ``Optional[np.random.RandomState]``.
  
      Returns:
          a Randomizable instance.
  
      """
      if seed is not None:
          _seed = (
              id(seed)
              if not isinstance(seed, (int, np.integer))
              else seed
          )
          _seed = _seed % MAX_SEED
          self.R = np.random.RandomState(_seed)
          return self
  
      if state is not None:
          if not isinstance(state, np.random.RandomState):
              raise TypeError(
                  f"state must be None or a np.random.RandomState but is {type(state).__name__}."
              )
          self.R = state
          return self
  
      self.R = np.random.RandomState()
      return self
  
imports: from __future__ import annotations
  import logging
  from abc import ABC, abstractmethod
  from collections.abc import Callable, Generator, Hashable, Iterable, Mapping
  from typing import Any, TypeVar
  import numpy
  import torch
  from monai import config, transforms
  from monai.config import KeysCollection
  from monai.data.meta_tensor import MetaTensor
  from monai.transforms.traits import LazyTrait, RandomizableTrait, ThreadUnsafe
  from monai.utils import MAX_SEED, ensure_tuple, first
  from monai.utils.enums import TransformBackends
  from monai.utils.misc import MONAIEnvVars
label_desc: Use image node_id 1 for calling the Randomizable obj's underlying member method code with example usage: obj.set_random_state(seed, state) and returns: self, self, self