code: def random_seeds_from_mask(
      mask,
      affine,
      seeds_count=1,
      seed_count_per_voxel=True,
      random_seed=None,
  ):
      """Create randomly placed seeds for fiber tracking from a binary mask.
  
      Seeds points are placed randomly distributed in voxels of ``mask``
      which are ``True``.
      If ``seed_count_per_voxel`` is ``True``, this function is
      similar to ``seeds_from_mask()``, with the difference that instead of
      evenly distributing the seeds, it randomly places the seeds within the
      voxels specified by the ``mask``.
  
      Parameters
      ----------
      mask : binary 3d array_like
          A binary array specifying where to place the seeds for fiber tracking.
      affine : array, (4, 4)
          The mapping between voxel indices and the point space for seeds.
          The voxel_to_rasmm matrix, typically from a NIFTI file.
          A seed point at the center the voxel ``[i, j, k]``
          will be represented as ``[x, y, z]`` where
          ``[x, y, z, 1] == np.dot(affine, [i, j, k , 1])``.
      seeds_count : int
          The number of seeds to generate. If ``seed_count_per_voxel`` is True,
          specifies the number of seeds to place in each voxel. Otherwise,
          specifies the total number of seeds to place in the mask.
      seed_count_per_voxel: bool
          If True, seeds_count is per voxel, else seeds_count is the total number
          of seeds.
      random_seed : int
          The seed for the random seed generator (numpy.random.Generator).
  
      See Also
      --------
      seeds_from_mask
  
      Raises
      ------
      ValueError
          When ``mask`` is not a three-dimensional array
  
      Examples
      --------
      >>> mask = np.zeros((3,3,3), 'bool')
      >>> mask[0,0,0] = 1
      >>> random_seeds_from_mask(mask, np.eye(4), seeds_count=1,
      ... seed_count_per_voxel=True, random_seed=1)
      array([[-0.23838787, -0.20150886,  0.31422574]])
      >>> random_seeds_from_mask(mask, np.eye(4), seeds_count=6,
      ... seed_count_per_voxel=True, random_seed=1)
      array([[-0.23838787, -0.20150886,  0.31422574],
             [-0.41435083, -0.26318949,  0.30127447],
             [ 0.44305611,  0.01132755,  0.47624371],
             [ 0.30500292,  0.30794079,  0.01532556],
             [ 0.03816435, -0.15672913, -0.13093276],
             [ 0.12509547,  0.3972138 ,  0.27568569]])
      >>> mask[0,1,2] = 1
      >>> random_seeds_from_mask(mask, np.eye(4),
      ... seeds_count=2, seed_count_per_voxel=True, random_seed=1)
      array([[ 0.30500292,  1.30794079,  2.01532556],
             [-0.23838787, -0.20150886,  0.31422574],
             [ 0.3702492 ,  0.78681721,  2.10314815],
             [-0.41435083, -0.26318949,  0.30127447]])
  
      """
      mask = np.array(mask, dtype=bool, copy=False, ndmin=3)
      if mask.ndim != 3:
          raise ValueError("mask cannot be more than 3d")
  
      # Randomize the voxels
      rng = np.random.default_rng(random_seed)
      shape = mask.shape
      mask = mask.flatten()
      indices = np.arange(len(mask))
      rng.shuffle(indices)
  
      where = [
          np.unravel_index(i, shape) for i in indices if mask[i] == 1
      ]
      num_voxels = len(where)
  
      if not seed_count_per_voxel:
          # Generate enough seeds per voxel
          seeds_per_voxel = seeds_count // num_voxels + 1
      else:
          seeds_per_voxel = seeds_count
  
      seeds = []
      for i in range(1, seeds_per_voxel + 1):
          for s in where:
              # Set the random seed with the current seed, the current value of
              # seeds per voxel and the global random seed.
              if random_seed is not None:
                  s_random_seed = hash(
                      (np.sum(s) + 1) * i + random_seed
                  ) % (2**32 - 1)
                  rng = np.random.default_rng(s_random_seed)
              # Generate random triplet
              grid = rng.random(3)
              seed = s + grid - 0.5
              seeds.append(seed)
      seeds = np.asarray(seeds)
  
      if not seed_count_per_voxel:
          # Select the requested amount
          seeds = seeds[:seeds_count]
  
      # Apply the spatial transform
      if seeds.any():
          # Use affine to move seeds into real world coordinates
          seeds = np.dot(seeds, affine[:3, :3].T)
          seeds += affine[:3, 3]
  
      return seeds
  
imports: from collections import defaultdict, OrderedDict
  from functools import wraps
  from itertools import combinations, groupby
  from warnings import warn
  import numpy
  from nibabel.affines import apply_affine
  from scipy.spatial.distance import cdist
  from dipy.core.geometry import dist_to_corner
  from dipy.tracking import metrics
  from dipy.tracking.vox2track import _streamlines_in_mask
  from dipy.tracking._utils import _mapping_to_voxel, _to_voxel_coordinates
label_desc: Use image node_id 7 for calling a global function with example usage: random_seeds_from_mask(mask, affine, seeds_count, seed_count_per_voxel, random_seed) and returns: seeds