code: def random_integers_helper(random_state, low, high, size):
      """
      Helper function to draw random integers.
  
      This is a generalization of numpy.random.random_integers to the case where
      low and high are tensors.
  
      Since random_integers is deprecated it calls randint() instead.
  
      """
      # Figure out the output shape
      if size is not None:
          out_ndim = len(size)
      else:
          out_ndim = max(low.ndim, high.ndim)
      # broadcast low and high to out_ndim dimensions
      if low.ndim > out_ndim:
          raise ValueError(
              "low.ndim (%i) should not be larger than len(size) (%i)"
              % (low.ndim, out_ndim),
              low,
              size,
          )
      if low.ndim < out_ndim:
          low = low.reshape((1,) * (out_ndim - low.ndim) + low.shape)
  
      if high.ndim > out_ndim:
          raise ValueError(
              "high.ndim (%i) should not be larger than len(size) (%i)"
              % (high.ndim, out_ndim),
              high,
              size,
          )
      if high.ndim < out_ndim:
          high = high.reshape(
              (1,) * (out_ndim - high.ndim) + high.shape
          )
  
      if size is not None:
          out_size = tuple(size)
      else:
          out_size = ()
          for dim in xrange(out_ndim):
              dim_len = max(low.shape[dim], high.shape[dim])
              out_size = out_size + (dim_len,)
  
      # Build the indices over which to loop
      out = np.ndarray(out_size)
      broadcast_ind = _generate_broadcasting_indices(
          out_size, low.shape, high.shape
      )
      # Iterate over these indices, drawing one sample at a time from numpy
      for oi, li, hi in zip(*broadcast_ind):
          out[oi] = random_state.randint(low=low[li], high=high[hi] + 1)
  
      return out
  
imports: from __future__ import absolute_import, print_function, division
  import sys
  from copy import copy
  import numpy
  from six import string_types
  from six.moves import reduce, xrange
  import theano
  from theano import tensor
  from theano.tensor import opt
  from theano import gof
  from theano.compile import optdb
label_desc: Use image node_id 6 for calling a global function with example usage: random_integers_helper(random_state, low, high, size) and returns: out