'Randomly sample the HMM to generate a sentence of a given length. This
samples the prior distribution then the observation distribution and
transition distribution for each subsequent observation and state.
This will mostly generate unintelligible garbage, but can provide some
amusement.
:return:        the randomly created state/observation sequence,
generated according to the HMM\'s probability
distributions. The SUBTOKENS have TEXT and TAG
properties containing the observation and state
respectively.
:rtype:         list
:param rng:     random number generator
:type rng:      Random (or any object with a random() method)
:param length:  desired output length
:type length:   int'

def random_sample(self, rng, length):

    tokens = []
    state = self._sample_probdist(self._priors, rng.random(), self._states)
    symbol = self._sample_probdist(self._outputs[state], rng.random(), self._symbols)
    tokens.append((symbol, state))
    for i in range(1, length):
        state = self._sample_probdist(self._transitions[state], rng.random(), self._states)
        symbol = self._sample_probdist(self._outputs[state], rng.random(), self._symbols)
        tokens.append((symbol, state))
    return tokens
