code: def random_cp(
      shape,
      rank,
      full=False,
      orthogonal=False,
      random_state=None,
      normalise_factors=True,
      **context,
  ):
      """Generates a random CP tensor
  
      Parameters
      ----------
      shape : tuple
          shape of the tensor to generate
      rank : int
          rank of the CP decomposition
      full : bool, optional, default is False
          if True, a full tensor is returned
          otherwise, the decomposed tensor is returned
      orthogonal : bool, optional, default is False
          if True, creates a tensor with orthogonal components
      random_state : `np.random.RandomState`
      context : dict
          context in which to create the tensor
  
      Returns
      -------
      random_cp : ND-array or 2D-array list
          ND-array : full tensor if `full` is True
          2D-array list : list of factors otherwise
      """
      rank = validate_cp_rank(shape, rank)
      if (rank > min(shape)) and orthogonal:
          warnings.warn(
              "Can only construct orthogonal tensors when rank <= min(shape) but got "
              f"a tensor with min(shape)={min(shape)} < rank={rank}"
          )
  
      rns = T.check_random_state(random_state)
      factors = [
          T.tensor(rns.random_sample((s, rank)), **context)
          for s in shape
      ]
      weights = T.ones(rank, **context)
      if orthogonal:
          factors = [T.qr(factor)[0] for factor in factors]
  
      if full:
          return cp_to_tensor((weights, factors))
      elif normalise_factors:
          return cp_normalize((weights, factors))
      else:
          return CPTensor((weights, factors))
  
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 3 for calling a global function with example usage: random_cp(shape, rank, full, orthogonal, random_state, normalise_factors) and returns: cp_to_tensor, cp_normalize, CPTensor