def sample_discrete(distn,size=[],dtype=np.int32):
distn = np.atleast_1d(distn)<EOL>assert (distn >=<NUM_LIT:0>).all() and distn.ndim == <NUM_LIT:1><EOL>if (<NUM_LIT:0> == distn).all():<EOL><INDENT>return np.random.randint(distn.shape[<NUM_LIT:0>],size=size)<EOL><DEDENT>cumvals = np.cumsum(distn)<EOL>return np.sum(np.array(random(size))[...,na] * cumvals[-<NUM_LIT:1>] > cumvals, axis=-<NUM_LIT:1>,dtype=dtype)<EOL>
samples from a one-dimensional finite pmf