Solved. I first made an n-length vector of random numbers between 0 and 1
and an indexing vector
k=(1:1:n), where n is the desired number of samples.
With p1, p2 etc. being the probabilities for each value of x, the signal becomes:
This assigns each possible value of x a portion of the interval between 0 and 1 corresponding to its probability p. For each k an entry from r is checked by all terms. They all evaluate to zero except the one that contains the number from r.