Algorithms for Generating Discrete Random Variables with a Given Generating Function or a Given Moment Sequence