code: def _randDense(states, actions, mask):
      
      # definition of transition matrix : square stochastic matrix
      P = _np.zeros((actions, states, states))
      # definition of reward matrix (values between -1 and +1)
      R = _np.zeros((actions, states, states))
      for action in range(actions):
          for state in range(states):
              # create our own random mask if there is no user supplied one
              if mask is None:
                  m = _np.random.random(states)
                  r = _np.random.random()
                  m[m <= r] = 0
                  m[m > r] = 1
              elif mask.shape == (actions, states, states):
                  m = mask[action][state]  # mask[action, state, :]
              else:
                  m = mask[state]
              # Make sure that there is atleast one transition in each state
              if m.sum() == 0:
                  m[_np.random.randint(0, states)] = 1
              P[action][state] = m * _np.random.random(states)
              P[action][state] = P[action][state] / P[action][state].sum()
              R[action][state] = (m * (2 * _np.random.random(states) -
                                  _np.ones(states, dtype=int)))
      return(P, R)
docs: Generate random dense ``P`` and ``R``. See ``rand`` for details.