code: def generate_random_img(
      shape,
      affine=np.eye(4),
      random_state=0,
  ):
      """Create a random 3D or 4D image with a given shape and affine.
  
      Parameters
      ----------
      shape : length-3 or length-4 tuple
          The shape of the image being generated.
          The number of elements determines the dimensionality of the image.
  
      affine : 4x4 numpy.ndarray
          The affine of the image
  
      random_state : int, optional
          Seed for random number generator.
  
      Returns
      -------
      data_img : 3D or 4D niimg
          The data image.
  
      mask_img : 3D niimg
          The mask image.
      """
      rng = np.random.default_rng(random_state)
      data = rng.standard_normal(size=shape)
      data_img = Nifti1Image(data, affine)
      if len(shape) == 4:
          mask_data = as_ndarray(data[..., 0] > 0.2, dtype=np.int8)
      else:
          mask_data = as_ndarray(data > 0.2, dtype=np.int8)
  
      mask_img = Nifti1Image(mask_data, affine)
  
      return data_img, mask_img
  
imports: from __future__ import annotations
  import itertools
  import json
  import string
  from pathlib import Path
  import numpy
  import pandas
  import scipy.linalg
  import scipy.signal
  from nibabel import Nifti1Image
  from scipy.ndimage import binary_dilation
  from nilearn import datasets, image, maskers, masking
  from nilearn._utils import as_ndarray, logger
  from nilearn.interfaces.bids.utils import bids_entities, check_bids_label, create_bids_filename
  from nilearn.interfaces.fmriprep.tests._testing import get_legal_confound
label_desc: Use image node_id 16 for calling a global function with example usage: generate_random_img(shape, affine, random_state) and returns: data_img,  mask_img