code: def rand(shape, dtype=np.float32, stream=None):
      from pycuda.gpuarray import GPUArray
      from pycuda.elementwise import get_elwise_kernel
  
      result = GPUArray(shape, dtype)
  
      if dtype == np.float32:
          func = get_elwise_kernel(
              "float *dest, unsigned int seed",
              md5_code
              + """
              #define POW_2_M32 (1/4294967296.0f)
              dest[i] = a*POW_2_M32;
              if ((i += total_threads) < n)
                  dest[i] = b*POW_2_M32;
              if ((i += total_threads) < n)
                  dest[i] = c*POW_2_M32;
              if ((i += total_threads) < n)
                  dest[i] = d*POW_2_M32;
              """,
              "md5_rng_float",
          )
      elif dtype == np.float64:
          func = get_elwise_kernel(
              "double *dest, unsigned int seed",
              md5_code
              + """
              #define POW_2_M32 (1/4294967296.0)
              #define POW_2_M64 (1/18446744073709551616.)
  
              dest[i] = a*POW_2_M32 + b*POW_2_M64;
  
              if ((i += total_threads) < n)
              {
                dest[i] = c*POW_2_M32 + d*POW_2_M64;
              }
              """,
              "md5_rng_float",
          )
      elif dtype in [np.int32, np.uint32]:
          func = get_elwise_kernel(
              "unsigned int *dest, unsigned int seed",
              md5_code
              + """
              dest[i] = a;
              if ((i += total_threads) < n)
                  dest[i] = b;
              if ((i += total_threads) < n)
                  dest[i] = c;
              if ((i += total_threads) < n)
                  dest[i] = d;
              """,
              "md5_rng_int",
          )
      else:
          raise NotImplementedError
  
      func.prepared_async_call(
          result._grid,
          result._block,
          stream,
          result.gpudata,
          np.random.randint(2**31 - 1),
          result.size,
      )
  
      return result
  
imports: import numpy
  import pycuda.compiler
  import pycuda.driver
  import pycuda.gpuarray
  from pytools import memoize_method
label_desc: Use image node_id 1 for calling a global function with example usage: rand(shape, dtype, stream) and returns: result