Question: how to create a distribution?

I create a continous random variable having an arbitrary pdf and characterize the corresponding distribution:

pdf := piecewise(a <= x and x <= b, 1, 0): f := unapply(pdf, x): R := Statistics:-RandomVariable(Statistics:-Distribution(PDF = f)): `assuming`([map(apply, [Statistics:-MGF, Statistics:-CGF, Statistics:-PDF, Statistics:-CDF, Statistics:-Moment], R, t)], [a < b]) ;

How do I do the same for a discrete random variable, of which only probabilities are known, e.g., P(x=1)=P(x=7)=1/2, to start with, or indeed P(x=a)=P(x=b)=1/2? How to create a new distribution with the specified probabilities, or a probability function? Tnanks. Also,  how to reduce the use of Statistics:- to minimum (e.g., in the last line of the code), not using with(Statistics)? Thanks.

Please Wait...