code: def gridpts(q, dist=None):
      """
      takes a list of lists of arbitrary length q = [[1,2],[3,4]]
      and produces a list of gridpoints g = [[1,3],[1,4],[2,3],[2,4]]
  
      Inputs:
          q  --  a list of lists of integers denoting grid points
          dist  --  a mystic.math.Distribution instance (or list of Distributions)
  
      Notes:
          if a mystic.math.Distribution is provided, use it to inject randomness
      """
      w = [[] for i in range(len(q[-1]))]
      for j in range(len(q) - 1, -1, -1):
          for k in range(len(q[j])):
              for l in range(
                  k * len(w) // len(q[j]), (k + 1) * len(w) // len(q[j])
              ):
                  w[l].append(q[j][k])
          if j:
              w += [i[:] for i in w[:] * (len(q[j - 1]) - 1)]
      pts = [list(reversed(w[i])) for i in range(len(w))]
      # inject some randomness
      if dist is None:
          return pts
      if not len(pts):
          return pts
      if hasattr(dist, "__len__"):  # FIXME: isiterable
          import numpy as np
  
          pts += np.array(tuple(di(len(pts)) for di in dist)).T
      else:
          pts += dist((len(pts), len(pts[0])))
      return pts.tolist()
  
label_desc: Use image node_id 1 for calling a global function with example usage: gridpts(q, dist) and returns: pts, pts, pts