The following pseudocode gives one approach to creating this sequence:
N = length of sequence to be simulated bkgd[r] = frequency of background sites with r read starts (r = 0, 1, 2, 3). for each i = 1...N x = random number between 0 and 1 (uniform distribution) if x < bkgd[0] sim_seq[i] = 0 else if x < bkgd[0] + bkgd[1] sim_seq[i] = 1 else if x < bkgd[0] + bkgd[1] + bkgd[2] sim_seq[i] = 2 else sim_seq[i] = 3
If there is a 0 in the denominator of your ratio (for cases where there were no D-segments for s), print -1.