search for: unif_rand

Displaying 20 results from an estimated 55 matches for "unif_rand".

2002 Nov 24
1
unif_rand() and exp_rand()
Dear R-users: Recently I found my simulation run into an apparently infinite loop. After a few days of tracing and chasing, I believe it is caused by the built-in unif_rand() and exp_rand() functions: unif_rand() can produce a value of 0 which causes the following part of exp_rand() running into an infinity loop u = unif_rand(); for (;;) { u += u; if (u > 1.0) break; a += q[0]; } The way I use R is slightly non-standard: I run the...
2004 Jun 15
2
About function "unif_rand()"
hello, everybody, I met a problem that I want to generate a random uniform number by using function with c interface. What I found is only "unif_rand()", but its range is [0,1]. How can I create a uniform random variable by using a function with c interface. Who can tell me what function it is and how to use? I will appreciate for it very much. Thanks in advance! xiaotong wang
2002 Jan 24
2
random number generation issues with r and compiled C code
...ear People, I have been writing a simulation routine that is currently entirely written in c++. I've been using the R standalone math library to give me random number generation for this. However, I have had to set the seed myself, and I am using set_seed(time(NULL), clock) for every call to unif_rand(). However, this works really badly. The random numbers aren't uniform at all. Does anyone have better suggestions? I think the problem is that every time I call the random number generation function, I have to set the seed, and this messes up the uniformity of the random number generation. T...
1997 Jun 03
1
R-alpha: unif_rand() again
Just out of curiosity, here is a question that might be embarrasingly stupid. Hmm ... What I need is to call runif() (more precisely, `runif(1, 0, 1)') from inside a C function. Is this possible using call_S? If so, how? -k =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send
2003 Jan 09
1
RNG.c: unif_rand, MARSAGLIA_MULTICARRY (PR#2437)
Full_Name: Richard Simard Version: OS: Linux Submission from: (NULL) (132.204.25.139) In the random number generator MARSAGLIA_MULTICARRY, your algorithm is different than the one in the original reference that you give in the R manual: Marsaglia in his post to the mailing list {\it sci.stat.math} on September 29, 1997. The last line in the R program has a ^ while Marsaglia's algorithm has
2018 Sep 19
4
Bias in R's random integers?
...h especially low (or especially high) probability. > > As I said in my original post, it's probably not hard to construct such > a thing, but as I've said more recently, it probably wouldn't happen by > chance. Here's one attempt to do it: > > Call the values from unif_rand() "the unif_rand() outcomes". Call the > values from sample() the sample outcomes. > > It would be easiest to see the error if half of the sample() outcomes > used two unif_rand() outcomes, and half used just one. That would mean > m should be (2/3) * 2^32, but that's...
2018 Sep 19
2
Bias in R's random integers?
.... Here's the code: (RNG.c, lines 793ff) double R_unif_index(double dn) { double cut = INT_MAX; switch(RNG_kind) { case KNUTH_TAOCP: case USER_UNIF: case KNUTH_TAOCP2: cut = 33554431.0; /* 2^25 - 1 */ break; default: break; } double u = dn > cut ? ru() : unif_rand(); return floor(dn * u); } On Wed, Sep 19, 2018 at 9:20 AM Duncan Murdoch <murdoch.duncan at gmail.com> wrote: > On 19/09/2018 12:09 PM, Philip B. Stark wrote: > > The 53 bits only encode at most 2^{32} possible values, because the > > source of the float is the output of...
2004 Mar 23
1
R equivilant to RAND_MAX in C
...the rand() manpage) However, since I have access to the R RNG's I'd like to use them. Firstly, would it be an improvement to use the R RNG over that supplied by the C library? Secondly, I dont see any mention of an equivilant to RAND_MAX in the documentation of runif() (as I want to use unif_rand() in my C code). Is it valid to use the C libraries' RAND_MAX as the maximum value of the RNG or am I missing something? As far as I understand using the .C interface I can't call R functions from my C code (which means I cant access runif()) - is this correct? As I would rather stay with...
2018 Sep 19
2
Bias in R's random integers?
...> > > As I said in my original post, it's probably not hard to construct > such > > a thing, but as I've said more recently, it probably wouldn't happen > by > > chance. Here's one attempt to do it: > > > > Call the values from unif_rand() "the unif_rand() outcomes". Call > the > > values from sample() the sample outcomes. > > > > It would be easiest to see the error if half of the sample() outcomes > > used two unif_rand() outcomes, and half used just one. That would > mean &gt...
2018 Sep 19
0
Bias in R's random integers?
...abundance of outcomes with especially low (or especially high) probability. As I said in my original post, it's probably not hard to construct such a thing, but as I've said more recently, it probably wouldn't happen by chance. Here's one attempt to do it: Call the values from unif_rand() "the unif_rand() outcomes". Call the values from sample() the sample outcomes. It would be easiest to see the error if half of the sample() outcomes used two unif_rand() outcomes, and half used just one. That would mean m should be (2/3) * 2^32, but that's too big and would tr...
2023 Feb 16
0
User-defined RNG with the standalone Rmath library
...nerator, which has poor properties. The "R Installation and Administration" manual, in the section "The standalone Rmath library", states that: ``` A little care is needed to use the random-number routines. You will need to supply the uniform random number generator double unif_rand(void) or use the one supplied (and with a shared library or DLL you may have to use the one supplied, which is the Marsaglia-multicarry with an entry point set_seed(unsigned int, unsigned int) to set its seeds). ``` I interpret this to mean that we cannot use a user-defined random number ge...
2008 Jul 03
1
GetRNGstate and PutRNGstate
Hi, I've got a simulation function, written in C and called from R, that uses the R random number functions. It's not a very complicated simulation - 280 lines total, with the main function (the one called with .C) repeatedly calling another function, with multiple calls to unif_rand() in both functions. At the beginning of the main function I call GetRNGstate(), and the last thing I do before returning to R is PutRNGstate(). On rereading Chapter 5 of the R Extensions manual, I'm not sure I understand the GetRNGstate/PutRNGstate calls. Should I also include them in the hel...
2017 Oct 18
1
uniform sampling without replacement algorithm
...case. This version is written to produce the same result as earlier versions, in which the algorithm was as follows (with x being temporary storage, and y being the result): for (i = 0; i < n; i++) x[i] = i; for (i = 0; i < k; i++) { j = n * unif_rand(); y[i] = x[j] + 1; x[j] = x[--n]; } When k <= 2, special code is used, for speed. When n is small or k is not much smaller than n, a modification of the above algorithm is used, which avoids the need for temporary storage - the result is allocated a...
2018 Sep 19
2
Bias in R's random integers?
...; >> ??? As I said in my original post, it's probably not hard to construct >> such >> ??? a thing, but as I've said more recently, it probably wouldn't >> happen by >> ??? chance.? Here's one attempt to do it: >> >> ??? Call the values from unif_rand() "the unif_rand() outcomes".? Call >> the >> ??? values from sample() the sample outcomes. >> >> ??? It would be easiest to see the error if half of the sample() outcomes >> ??? used two unif_rand() outcomes, and half used just one.? That would >> mean...
2018 Sep 20
5
Bias in R's random integers?
...on-integer arguments to sample size). Otherwise, an R package binding > seems like a good starting point, but I'm not the right volunteer. It is difficult to do this in a package, since R does not provide access to the random bits generated by the RNG. Only a float in (0,1) is available via unif_rand(). However, if one is willing to use an external RNG, it is of course possible. After reading about Lemire's work [1], I had planned to integrate such an unbiased sampling scheme into the dqrng package, which I have now started. [2] Using Duncan's example, the results look much better: &g...
2019 Mar 01
1
issue with sample in R 3.6.0.
...we see that if N is greater than 2^31, then N is bounded by (2^(ceiling(log2(N)) ? 32)). Looking at the source code to src/main/RNG.c, we have the following: static double rbits(int bits) { int_least64_t v = 0; for (int n = 0; n <= bits; n += 16) { int v1 = (int) floor(unif_rand() * 65536); v = 65536 * v + v1; } // mask out the bits in the result that are not needed return (double) (v & ((1L << bits) - 1)); } The last line has (v & ((1L << bits) - 1)) where v is declared as int_least64_t. If you notice, we are operating on v...
2018 Sep 19
0
Bias in R's random integers?
...ally high) > probability. > > As I said in my original post, it's probably not hard to construct such > a thing, but as I've said more recently, it probably wouldn't happen by > chance.? Here's one attempt to do it: > > Call the values from unif_rand() "the unif_rand() outcomes".? Call the > values from sample() the sample outcomes. > > It would be easiest to see the error if half of the sample() outcomes > used two unif_rand() outcomes, and half used just one.? That would mean > m should be (2/3) * 2^3...
2009 Nov 13
2
random numbers in C
I need some random numbers in my C program. Here a small example: //////////////////////////////////////////////////////////////////////////////// #include <R.h> void rand (int* n) { int len = *n; for (int i = 0; i < len; i++) Rprintf("%1.5f ", unif_rand()); } dyn.load("rand.dll") .C("rand", as.integer(10)) dyn.unload("rand.dll") //////////////////////////////////////////////////////////////////////////////// But this gives me 10 times the number 0.00000 (I need 10 numbers between 0 and 1). Can somebody give me a hin...
2018 Sep 19
0
Bias in R's random integers?
...original post, it's probably not hard to construct > >> such > >> a thing, but as I've said more recently, it probably wouldn't > >> happen by > >> chance. Here's one attempt to do it: > >> > >> Call the values from unif_rand() "the unif_rand() outcomes". Call > >> the > >> values from sample() the sample outcomes. > >> > >> It would be easiest to see the error if half of the sample() > outcomes > >> used two unif_rand() outcomes, and half used just...
2018 Sep 19
0
Bias in R's random integers?
...in my original post, it's probably not hard to > construct such > >? ? ?a thing, but as I've said more recently, it probably wouldn't > happen by > >? ? ?chance.? Here's one attempt to do it: > > > >? ? ?Call the values from unif_rand() "the unif_rand() outcomes". > Call the > >? ? ?values from sample() the sample outcomes. > > > >? ? ?It would be easiest to see the error if half of the sample() > outcomes > >? ? ?used two unif_rand() outcomes, and half used ju...