<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def sample_discrete(self, state=None, n_steps=100, random_state=None):
 r"""Generate a random sequence of states by propagating the model using discrete time steps given by the model lagtime. Parameters state : {None, ndarray, label} Specify the starting state for the chain. ``None`` Choose the initial state by randomly drawing from the model's stationary distribution. ``array-like`` If ``state`` is a 1D array with length equal to ``n_states_``, then it is is interpreted as an initial multinomial distribution from which to draw the chain's initial state. Note that the indexing semantics of this array must match the _internal_ indexing of this model. otherwise Otherwise, ``state`` is interpreted as a particular deterministic state label from which to begin the trajectory. n_steps : int Lengths of the resulting trajectory random_state : int or RandomState instance or None (default) Pseudo Random Number generator seed control. If None, use the numpy.random singleton. Returns ------- sequence : array of length n_steps A randomly sampled label sequence """

        random = check_random_state(random_state)
        r = random.rand(1 + n_steps)

        if state is None:
            initial = np.sum(np.cumsum(self.populations_) < r[0])
        elif hasattr(state, '__len__') and len(state) == self.n_states_:
            initial = np.sum(np.cumsum(state) < r[0])
        else:
            initial = self.mapping_[state]

        cstr = np.cumsum(self.transmat_, axis=1)

        chain = [initial]
        for i in range(1, n_steps):
            chain.append(np.sum(cstr[chain[i - 1], :] < r[i]))

        return self.inverse_transform([chain])[0]