code: def register_random(r: RandomLike) -> None:
      """Register (a weakref to) the given Random-like instance for management by
      Hypothesis.
  
      You can pass instances of structural subtypes of ``random.Random``
      (i.e., objects with seed, getstate, and setstate methods) to
      ``register_random(r)`` to have their states seeded and restored in the same
      way as the global PRNGs from the ``random`` and ``numpy.random`` modules.
  
      All global PRNGs, from e.g. simulation or scheduling frameworks, should
      be registered to prevent flaky tests. Hypothesis will ensure that the
      PRNG state is consistent for all test runs, always seeding them to zero and
      restoring the previous state after the test, or, reproducibly varied if you
      choose to use the :func:`~hypothesis.strategies.random_module` strategy.
  
      ``register_random`` only makes `weakrefs
      <https://docs.python.org/3/library/weakref.html#module-weakref>`_ to ``r``,
      thus ``r`` will only be managed by Hypothesis as long as it has active
      references elsewhere at runtime. The pattern ``register_random(MyRandom())``
      will raise a ``ReferenceError`` to help protect users from this issue.
      This check does not occur for the PyPy interpreter. See the following example for
      an illustration of this issue
  
      .. code-block:: python
  
  
         def my_BROKEN_hook():
             r = MyRandomLike()
  
             # `r` will be garbage collected after the hook resolved
             # and Hypothesis will 'forget' that it was registered
             register_random(r)  # Hypothesis will emit a warning
  
  
         rng = MyRandomLike()
  
  
         def my_WORKING_hook():
             register_random(rng)
      """
      if not (
          hasattr(r, "seed")
          and hasattr(r, "getstate")
          and hasattr(r, "setstate")
      ):
          raise InvalidArgument(
              f"{r=} does not have all the required methods"
          )
  
      if r in RANDOMS_TO_MANAGE.values():
          return
  
      if not (PYPY or GRAALPY):  # pragma: no branch
          # PYPY and GRAALPY do not have `sys.getrefcount`
          gc.collect()
          if not gc.get_referrers(r):
              if sys.getrefcount(r) <= _PLATFORM_REF_COUNT:
                  raise ReferenceError(
                      f"`register_random` was passed `r={r}` which will be "
                      "garbage collected immediately after `register_random` creates a "
                      "weakref to it. This will prevent Hypothesis from managing this "
                      "PRNG. See the docs for `register_random` for more "
                      "details."
                  )
              else:
                  warnings.warn(
                      "It looks like `register_random` was passed an object that could "
                      "be garbage collected immediately after `register_random` creates "
                      "a weakref to it. This will prevent Hypothesis from managing this "
                      "PRNG. See the docs for `register_random` for more details.",
                      HypothesisWarning,
                      stacklevel=2,
                  )
  
      RANDOMS_TO_MANAGE[next(_RKEY)] = r
  
file_path: catboost/contrib/python/hypothesis/py3/hypothesis/internal/entropy.py
imports: import contextlib
  import gc
  import random
  import sys
  import warnings
  from itertools import count
  from typing import TYPE_CHECKING, Any, Callable, Hashable, Tuple
  from weakref import WeakValueDictionary
  import hypothesis.core
  from hypothesis.errors import HypothesisWarning, InvalidArgument
  from hypothesis.internal.compat import GRAALPY, PYPY
label_desc: Use image node_id 1 for calling a global function with example usage: register_random(r) without return types