I'm trying to draw a random sample from 1,2,3,4 under a given probability vector of length four in C, with the help of Rmath.h. I found this line of code could do this for me.
inline void rmultinom(int n, double* prob, int k, int* rn)
For example, I can write it to draw one random sample.
double p[4]={.1, .2, .3, .2};
rmultinom(1, p, 1, int* rn)
However, I'm lost what this 4th argument should be. In R, the rmultinom function only requires the first three arguments. Another question is what is returned from this function. Is there any convenient way for it to return with one of 1, 2, 3, 4?