code: def randimg_in2out(rng, in_dtype, out_dtype, name):
      in_dtype = np.dtype(in_dtype)
      out_dtype = np.dtype(out_dtype)
      shape = (2, 3, 4)
      if in_dtype.kind in "iu":
          info = np.iinfo(in_dtype)
          dmin, dmax = info.min, info.max
          # Numpy bug for np < 1.6.0 allows overflow for range that does not fit
          # into C long int (int32 on 32-bit, int64 on 64-bit)
          try:
              data = rng.randint(dmin, dmax, size=shape)
          except ValueError:
              from random import randint
  
              vals = [
                  randint(dmin, dmax) for v in range(np.prod(shape))
              ]
              data = np.array(vals).astype(in_dtype).reshape(shape)
      elif in_dtype.kind == "f":
          info = np.finfo(in_dtype)
          dmin, dmax = info.min, info.max
          # set some value for scaling our data
          scale = np.iinfo(np.uint16).max * 2.0
          data = rng.normal(size=shape, scale=scale)
      data[0, 0, 0] = dmin
      data[1, 0, 0] = dmax
      data = data.astype(in_dtype)
      img = Image(data, vox2mni(np.eye(4)))
      # The dtype_from dtype won't be visible until the image is loaded
      newimg = save_image(img, name, dtype_from=out_dtype)
      return newimg.get_fdata(), data
  
imports: from os.path import dirname
  from os.path import join
  import nibabel
  import numpy
  import pytest
  from nibabel import Nifti1Header
  from nibabel.filebasedimages import ImageFileError
  from nibabel.spatialimages import HeaderDataError
  from nibabel.tests.test_round_trip import big_bad_ulp
  from nipy.core.api import AffineTransform
  from nipy.core.api import Image, vox2mni
  from nipy.testing import anatfile, assert_almost_equal, assert_array_almost_equal, assert_array_equal, funcfile
  from nipy.testing.decorators import if_templates
  from nipy.utils import DataError, templates
  from ..api import as_image, load_image, save_image
label_desc: Use image node_id 5 for calling a global function with example usage: randimg_in2out(rng, in_dtype, out_dtype, name) and returns: newimg,  data