Re: [R] Code of sample() in C

2009-04-06 Thread Paul Smith
Thanks again, Ranjan. I am wondering whether the seed can be set (renewed) with GetRNGstate(). Furthermore, I would like to understand why I am getting the reported compilation errors when I insert GetRNGstate() in my code. Paul On Mon, Apr 6, 2009 at 12:17 PM, Ranjan Maitra wrote: > Hi Paul, >

Re: [R] Code of sample() in C

2009-04-06 Thread Ranjan Maitra
Hi Paul, I believe that you may need to set seed differently when you call the R math library as standalone. Specifically, you need to do the following (or rather, the following works): unsigned int seed1, seed2; FILE *fran; fran = fopen("random.seed","r");

Re: [R] Code of sample() in C

2009-04-06 Thread Paul Smith
Thanks, Ranjan! I have tried to use the function SampleNoReplace in random.c, which seems to work, except that I get always the same random numbers (with your code the same happens). (My code is below.). I have read the documentation ("Writing R extensions"), where it is advised: «The interface t

Re: [R] Code of sample() in C

2009-04-05 Thread Berwin A Turlach
G'day Ranjan, On Sun, 5 Apr 2009 17:00:56 -0500 Ranjan Maitra wrote: > [...[ > I haven't tried this function out much myself, so YMMV. There is an obvious problem in this code since len is not decreased but n is when an index is sampled. The last line in the last for loop should be x[j

Re: [R] Code of sample() in C

2009-04-05 Thread Ranjan Maitra
I presume you mean sampling without replacement? The following (adapted from the file you asked for) will do it, but you will need to incorporate Rmath as standalone in order to get runif to work. This function will give you k indices from n, sampled WOR. Thus, n = 50 for you and k = 5. You will g

Re: [R] Code of sample() in C

2009-04-05 Thread Paul Smith
Thanks, Ranjan. Got it! I am now wondering whether there is some simpler way of implementing the following in C: sample(1:50,5) Paul On Sun, Apr 5, 2009 at 4:10 PM, Ranjan Maitra wrote: > Hi Paul, > > It is in the main/src/random.c file of the source code. > > HTH! > Best wishes, > Ranjan > >

Re: [R] Code of sample() in C

2009-04-05 Thread Ranjan Maitra
Hi Paul, It is in the main/src/random.c file of the source code. HTH! Best wishes, Ranjan On Sun, 5 Apr 2009 15:35:25 +0100 Paul Smith wrote: > Dear All, > > I would like to use the function sample() in a program written in C. > Is there somewhere the code of sample() written in C? > > Thank

[R] Code of sample() in C

2009-04-05 Thread Paul Smith
Dear All, I would like to use the function sample() in a program written in C. Is there somewhere the code of sample() written in C? Thanks in advance, Paul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do re