Dear all, I am trying to learn functions in R and 3D plotting so I decided to try to plot the famous bad PRNG Randu from IBM(1). However something is not correct in the function I have created. First I define the function RANDU like this:
> RANDU <- function(num) { return (65539*num)%%(2^31) } and test that it works for a seed of 1: > RANDU(1) [1] 65539 but if I want the next value in the sequence I get this number. > (65539*65539)%%(2^31) [1] 393225 However using the RANDU function twice doesn't give the same result as above. > RANDU(RANDU(1)) [1] 4295360521 I expect these two values to be the same but that is not the case. 393225 should be the correct. I guess it might be something with local vs. global environment ?! Please advise and thanks. Regards Martin M. S. Pedersen (1) https://en.wikipedia.org/wiki/RANDU [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.