code: def random_parafac2(
      shapes,
      rank,
      full=False,
      random_state=None,
      normalise_factors=False,
      **context,
  ):
      """Generate a random PARAFAC2 tensor
  
      Parameters
      ----------
      shape : tuple
          A tuple where each element represents the shape of a matrix
          represented by the PARAFAC2 model. The second element in each
          shape-tuple must be
          constant.
      rank : int or int list
          rank of the Parafac2 decomposition
      full : bool, optional, default is False
          if True, a full tensor is returned otherwise,
          the decomposed tensor is returned
      random_state : `np.random.RandomState`
      """
      rns = T.check_random_state(random_state)
      if not all(shape[1] == shapes[0][1] for shape in shapes):
          raise ValueError(
              "All matrices must have equal number of columns."
          )
  
      projection_matrices = [
          T.qr(
              T.tensor(rns.random_sample((shape[0], rank)), **context)
          )[0]
          for shape in shapes
      ]
      weights, factors = random_cp(
          [len(shapes), rank, shapes[0][1]],
          rank=rank,
          normalise_factors=False,
          random_state=rns,
          **context,
      )
  
      parafac2_tensor = Parafac2Tensor(
          (weights, factors, projection_matrices)
      )
  
      if normalise_factors:
          parafac2_tensor = parafac2_normalise(parafac2_tensor)
  
      if full:
          return parafac2_to_tensor(parafac2_tensor)
      else:
          return parafac2_tensor
  
file_path: tensorly/tensorly/random/base.py
imports: import numpy
  from ..cp_tensor import cp_to_tensor, CPTensor, cp_normalize, validate_cp_rank
  from ..tucker_tensor import tucker_to_tensor, TuckerTensor, validate_tucker_rank
  from ..tt_tensor import tt_to_tensor, TTTensor, validate_tt_rank
  from ..tt_matrix import tt_matrix_to_tensor, TTMatrix, validate_tt_matrix_rank
  from ..tr_tensor import TRTensor, tr_to_tensor, validate_tr_rank
  from ..parafac2_tensor import parafac2_to_tensor, Parafac2Tensor, parafac2_normalise
  from ..None import backend
  import warnings
label_desc: Use image node_id 2 for calling a global function with example usage: random_parafac2(shapes, rank, full, random_state, normalise_factors) and returns: parafac2_to_tensor, parafac2_tensor