On Mon, 30 Apr 2012, Vale Fara wrote:

ok, what to do is to generate two sets (x,y) of integer uniform random numbers so that the following condition is satisfied: the sum of the numbers obtained in x,y matched two by two (first number obtained in x with first number obtained in y and so on) is in mean equal to a value z, mean value that I can decide before the randomization.

Hope this is more clear than before...

It isn't very clear to me. If you generate random X,Y pairs such that (X+Y)/2=z, then you have a only one random number and a nother that is completely dependent on it:

X = random
Y = 2z - X.

I'll just tell you one thing you might be able to use, but I don't have time for this.

To make a vector of N uniformly-distributed random integers in the range from integer A to integer B, inclusive, you can do this:

floor( runif(N, min=A, max=B+1) )

The floor() function rounds down to the nearest integer. Depending on the exact nature of the algorithm, it might be possible for B+1 to happen, but it would be extremely unlikely, if it really is possible.

This should do the same thing:

floor((B-A+1)*runif(N)+A)

The ceiling function can accomplish the same thing. To make random integers from 1 to K, do this:

ceiling( K*runif(N) )

Mike

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to