Solved. I first made an n-length vector of random numbers between 0 and 1

r=rand(1,n)

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:

x(k)=x1*(r(k)<p1)+x2*((r(k)>=p1)&(r(k)<p1+p2))+...

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.