code: def make_numba_random_fn(node, np_random_func):
      """Create Numba implementations for existing Numba-supported ``np.random`` functions.
  
      The functions generated here add parameter broadcasting and the ``size``
      argument to the Numba-supported scalar ``np.random`` functions.
      """
      if not isinstance(node.inputs[0].type, RandomStateType):
          raise TypeError("Numba does not support NumPy `Generator`s")
  
      tuple_size = int(get_vector_length(node.inputs[1]))
      size_dims = tuple_size - max(i.ndim for i in node.inputs[3:])
  
      # Make a broadcast-capable version of the Numba supported scalar sampling
      # function
      bcast_fn_name = (
          f"pytensor_random_{get_name_for_object(np_random_func)}"
      )
  
      sized_fn_name = "sized_random_variable"
  
      unique_names = unique_name_generator(
          [
              bcast_fn_name,
              sized_fn_name,
              "np",
              "np_random_func",
              "numba_vectorize",
              "to_fixed_tuple",
              "tuple_size",
              "size_dims",
              "rng",
              "size",
              "dtype",
          ],
          suffix_sep="_",
      )
  
      bcast_fn_input_names = ", ".join(
          [unique_names(i, force_unique=True) for i in node.inputs[3:]]
      )
      bcast_fn_global_env = {
          "np_random_func": np_random_func,
          "numba_vectorize": numba_basic.numba_vectorize,
      }
  
      bcast_fn_src = f"""
  @numba_vectorize
  def {bcast_fn_name}({bcast_fn_input_names}):
      return np_random_func({bcast_fn_input_names})
      """
      bcast_fn = compile_function_src(
          bcast_fn_src,
          bcast_fn_name,
          {**globals(), **bcast_fn_global_env},
      )
  
      random_fn_input_names = ", ".join(
          ["rng", "size", "dtype"]
          + [unique_names(i) for i in node.inputs[3:]]
      )
  
      # Now, create a Numba JITable function that implements the `size` parameter
      out_dtype = node.outputs[1].type.numpy_dtype
      random_fn_global_env = {
          bcast_fn_name: bcast_fn,
          "out_dtype": out_dtype,
      }
  
      if tuple_size > 0:
          random_fn_body = dedent(
              f"""
          size = to_fixed_tuple(size, tuple_size)
  
          data = np.empty(size, dtype=out_dtype)
          for i in np.ndindex(size[:size_dims]):
              data[i] = {bcast_fn_name}({bcast_fn_input_names})
  
          """
          )
          random_fn_global_env.update(
              {
                  "np": np,
                  "to_fixed_tuple": numba_ndarray.to_fixed_tuple,
                  "tuple_size": tuple_size,
                  "size_dims": size_dims,
              }
          )
      else:
          random_fn_body = (
              f"""data = {bcast_fn_name}({bcast_fn_input_names})"""
          )
  
      sized_fn_src = dedent(
          f"""
  def {sized_fn_name}({random_fn_input_names}):
  {indent(random_fn_body, " " * 4)}
      return (rng, data)
      """
      )
      random_fn = compile_function_src(
          sized_fn_src,
          sized_fn_name,
          {**globals(), **random_fn_global_env},
      )
      random_fn = numba_basic.numba_njit(random_fn)
  
      return random_fn
  
imports: from textwrap import dedent, indent
  from typing import Any, Callable, Optional
  import numba.np.unsafe.ndarray
  import numpy
  from numba import _helperlib, types
  from numba.core import cgutils
  from numba.extending import NativeValue, box, models, register_model, typeof_impl, unbox
  from numpy.random import RandomState
  import pytensor.tensor.random.basic
  from pytensor.graph.basic import Apply
  from pytensor.graph.op import Op
  from pytensor.link.numba.dispatch import basic
  from pytensor.link.numba.dispatch.basic import numba_funcify, numba_typify
  from pytensor.link.utils import compile_function_src, get_name_for_object, unique_name_generator
  from pytensor.tensor.basic import get_vector_length
  from pytensor.tensor.random.type import RandomStateType
label_desc: Use image node_id 5 for calling a global function with example usage: make_numba_random_fn(node, np_random_func) and returns: random_fn