search for: rand_max

Displaying 20 results from an estimated 25 matches for "rand_max".

2004 Mar 23
1
R equivilant to RAND_MAX in C
Hello, I have some C code that I'm interfacing to R using the .C calling interface. Currently the C code uses the rand() function from the GNU C library to generate random numbers. Since I need the random numbers in a range from 0 to a (where a is an integer) I use the RAND_MAX macro as (int)(rand() * (float)(*nobs-1) / (RAND_MAX+1.0)) (taken from 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...
1999 Feb 05
0
Installing R programs (PROBLEMS !!!!)
...ected the following problem which makes Samira> impossible to run R. We have got the following message: Samira> ======= Samira> gcc -g -O2 -I../include -I../../src/include -c sunif.c -o sunif.o Samira> sunif.c: In function `unif_rand': Samira> sunif.c:131: `RAND_MAX' undeclared (first use this function) Samira> sunif.c:131: (Each undeclared identifier is reported only once Samira> sunif.c:131: for each function it appears in.) Samira> sunif.c: In function `Randomize': Samira> sunif.c:213: `NULL' undeclared (first use thi...
2000 Dec 11
1
fixing shuffle in ogg123
...t; argc; i++) + int i; + int nb = argc - optind; + int *p = alloca(sizeof(int) * nb); + for (i = 0; i < nb; i++) p[i] = i; + + srand (time (NULL)); + for (i = 1; i < nb; i++) { - srand (time (NULL)); - j = (int) ((float) (argc - optind) * rand () / (RAND_MAX + 1.0)); - param.read_file = argv[j+optind]; + int j = i * ((float) rand() / RAND_MAX); + int temp = p[j]; p[j] = p[i]; p[i] = temp; + } + for (i = 0; i < nb; i++) + { + param.read_file = argv[p[i]+optind]; play_file (); } } -=-=-- -- Guillaume Cottence...
1999 Feb 05
0
[Fwd] Problems installing R on SunOS 4.1.4
...ected the following problem which makes Samira> impossible to run R. We have got the following message: Samira> ======= Samira> gcc -g -O2 -I../include -I../../src/include -c sunif.c -o sunif.o Samira> sunif.c: In function `unif_rand': Samira> sunif.c:131: `RAND_MAX' undeclared (first use this function) Samira> sunif.c:131: (Each undeclared identifier is reported only once Samira> sunif.c:131: for each function it appears in.) Samira> sunif.c: In function `Randomize': Samira> sunif.c:213: `NULL' undeclared (first use thi...
2003 Apr 07
4
4-stable and C rand()?
Hi everyone, sorry if this has been answered before - I caught a whiff of a discussion about c's rand() function in a mailing list archive, but couldn't find a definitive answer. I'm trying to do a simple CS project on my machine where I generate two sets of values in parallel using rand() and am running into infinite loops of values, and couldn't figure out why, so I wrote a test
1999 Feb 24
2
Compiling R on Sunos
.../../src/include -c bessel_y.c -o bessel_y.o gcc -g -O2 -I../include -I../../src/include -c choose.c -o choose.o gcc -g -O2 -I../include -I../../src/include -c snorm.c -o snorm.o gcc -g -O2 -I../include -I../../src/include -c sunif.c -o sunif.o sunif.c: In function `unif_rand': sunif.c:131: `RAND_MAX' undeclared (first use in this function) sunif.c:131: (Each undeclared identifier is reported only once sunif.c:131: for each function it appears in.) sunif.c: In function `Randomize': sunif.c:213: `NULL' undeclared (first use in this function) make[2]: *** [sunif.o] Error 1 make[2]: Le...
2004 Sep 28
3
[LLVMdev] patches and problem...
...xt major problem is that VC has only int rand(void) void srand( int seed ) So I donno how to compile the ExecutionEngine/Interpreter/ExternalFunctions.cpp that refers to the drand48 srand48 lrand48 etc series... For now I hacked them, like double drand48(void) { return (float) rand() / (float) RAND_MAX and so... Is it -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: diffs.txt URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20040928/49dba439/attachment.txt> -------------- next part -------------- not more portable if the rand...
2004 Sep 28
0
[LLVMdev] patches and problem...
...; int rand(void) > void srand( int seed ) > > So I donno how to compile the > ExecutionEngine/Interpreter/ExternalFunctions.cpp that refers to the > drand48 srand48 lrand48 etc series... > For now I hacked them, like > > double drand48(void) { return (float) rand() / (float) RAND_MAX For these, just ifdef them out. If the platform doesn't support drand48, there is no reason for the interpreter to do so either... -Chris -- http://llvm.org/ http://nondot.org/sabre/
2003 Aug 25
1
Re: R 1.7.x and inaccurate log1p() on OpenBSD 3.2 and NetBSD 1.6 (PR#3979)
...00 99 1.577721810442024e-30 1.577721810442024e-30 0.00e+00 100 7.888609052210118e-31 7.888609052210118e-31 0.00e+00 At least for test arguments of the form 2^(-k), my LOG1P() is identical to log1p(). A simple change to that test program, inserting x *= (double)rand() / (double)(RAND_MAX); after the assignment to x to pick a random value near a power of k, produces output like this: % cc cmp-log1p-2.c -lm && ./a.out 0 4.146697237286190e-01 4.146697237286190e-01 0.00e+00 1 8.421502722841255e-02 8.421502722841256e-02 1.65e-16 2 7.432648260535767e-0...
2009 Apr 03
1
Hello! I got error in C - R
..._Edges(M1, n); M2_STAT[0] = Count_Edges(M2, n); M1_STAT[1] = Cal_GWD(M1, n); M2_STAT[1] = Cal_GWD(M2, n); pi_Num = Inner_Product(theta_new, M1_STAT, n_para); pi_Denom = Inner_Product(theta_new, M2_STAT, n_para); MH_Ratio = pi_Num - pi_Denom; srand(rdtsc()); v = (double)rand() / ( (double)RAND_MAX + (double)1 ); if( log( v ) < Min( 0, MH_Ratio ) ) return 1; else return 0; free(M1_STAT); free(M2_STAT); } double Count_Edges(int *X, int n) { double temp; int i, j; temp = 0; for(i = 1; i < n; i++) { for(j = 0; j < i; j++) { temp += X[i * n + j]; } } return...
2015 Sep 04
0
getting a vector of unown size
...then shrink the vector to the size where meaningful values occur, but this waste much resources and time unnecessarily. The C code #include <stdlib.h> #include <math.h> double min(double a, double b) { if(a>b) return b; else return a; } double unirand() { return (rand()+1.0)/(RAND_MAX+1.0); } void RndSBDdemography(double *b, double *d, double *a, double *c, double *No, double *tmax, double *tiempo, double *Nind) { double tb, td, n; int bc=0; tiempo[0]=1.0; Nind[0] = *No; // This loop generates output of variable and a priori unknown size while (Nind[bc] >= 2 && ti...
2004 Sep 29
2
[LLVMdev] patches and problem...
...oid srand( int seed ) >> >>So I donno how to compile the >>ExecutionEngine/Interpreter/ExternalFunctions.cpp that refers to the >>drand48 srand48 lrand48 etc series... >>For now I hacked them, like >> >>double drand48(void) { return (float) rand() / (float) RAND_MAX > > > For these, just ifdef them out. If the platform doesn't support drand48, > there is no reason for the interpreter to do so either... > > -Chris >
2013 May 09
2
opus file trimming/clipping
...approach and how do I then specify where the decoding is supposed to stop? I will describe the steps I've tried so far (maybe not the best approach): I have tried modifying the opusfile-1.0.2/examples/seeking_example.c as a base, replacing pcm_offset=(ogg_int64_t)(rand()/(double)RAND_MAX*pcm_length); with pcm_offset=(ogg_int64_t)((double)pcm_length/2.0); presumably to start the decoding at the middle of the file by: ret=op_pcm_seek(of,pcm_offset); However, when I save the file using the write_samples(buffer,nsamples,nchannels) function, the file is unr...
2010 Dec 24
0
mcga 1.1 (machine coded genetic algorithms) package released
...ds for the mutation operator. In mcga, we randomly change a byte like this: ________________________________ void GA::Mutate(Chromosome *c1){ char *cptr=(char *)c1->values; int mutatepoint=(rand() % (this->chsize * sizeof(double))); cptr+=mutatepoint; if(((float)rand()/RAND_MAX)<0.5){ (*cptr)+=1; }else{ (*cptr)-=1; } } ________________________________ Changing a byte of a double value can make a small or extremely high difference. This is the mutation operator of mcga. This chromosome coding strategy has some advantages: 1)...
2010 Dec 24
0
mcga 1.1 (machine coded genetic algorithms) package released
...ds for the mutation operator. In mcga, we randomly change a byte like this: ________________________________ void GA::Mutate(Chromosome *c1){ char *cptr=(char *)c1->values; int mutatepoint=(rand() % (this->chsize * sizeof(double))); cptr+=mutatepoint; if(((float)rand()/RAND_MAX)<0.5){ (*cptr)+=1; }else{ (*cptr)-=1; } } ________________________________ Changing a byte of a double value can make a small or extremely high difference. This is the mutation operator of mcga. This chromosome coding strategy has some advantages: 1)...
2011 Jan 28
2
klibc 1.5.21-1 and mksh
...extern unsigned short *seed48(const unsigned short *); + __extern void srand48(long); + ++/* arc4random API emulation on top of jrand48 algorithm */ ++__extern uint32_t arc4random(void); ++__extern void arc4random_stir(void); ++__extern void arc4random_addrandom(unsigned char *, int); ++ + #define RAND_MAX 0x7fffffff + static __inline__ int rand(void) + { +Index: klibc-1.5.21/usr/klibc/Kbuild +=================================================================== +--- klibc-1.5.21.orig/usr/klibc/Kbuild 2011-01-28 12:00:27.000000000 +0000 ++++ klibc-1.5.21/usr/klibc/Kbuild 2011-01-28 12:01:27.000000000 +...
2018 Dec 28
1
[PATCH nbdkit] common: Improve pseudo-random number generation.
...n false; @@ -278,12 +272,12 @@ random_error (struct handle *h, if (error_settings->rate >= 1) /* 100% = always inject */ goto inject; -#ifdef __GNU_LIBRARY__ - random_r (&h->rd, &rand); -#else - rand = random (); -#endif - if (rand >= error_settings->rate * RAND_MAX) + /* To avoid the question if (double)1.0 * UINT64_MAX is + * representable in a 64 bit integer, and because we don't need all + * this precision anyway, let's work in 32 bits. + */ + rand = xrandom (&h->random_state) & UINT32_MAX; + if (rand >= error_settings->ra...
2018 Dec 28
0
[PATCH v2 nbdkit] common: Improve pseudo-random number generation.
...n false; @@ -278,12 +272,12 @@ random_error (struct handle *h, if (error_settings->rate >= 1) /* 100% = always inject */ goto inject; -#ifdef __GNU_LIBRARY__ - random_r (&h->rd, &rand); -#else - rand = random (); -#endif - if (rand >= error_settings->rate * RAND_MAX) + /* To avoid the question if (double)1.0 * UINT64_MAX is + * representable in a 64 bit integer, and because we don't need all + * this precision anyway, let's work in 32 bits. + */ + rand = xrandom (&h->random_state) & UINT32_MAX; + if (rand >= error_settings->ra...
2018 Dec 28
2
[PATCH v2 nbdkit] common: Improve pseudo-random number generation.
v2: - Fix seeding. - Add a test that nbdkit-random-plugin is producing something which looks at least somewhat random. Rich.
2008 Apr 04
0
speexdec 1.2.3
...rint_comments((char*)op.packet, op.bytes); } else if (packet_count<=1+extra_headers) { /* Ignore extra headers */ } else { int lost=0; packet_no++; if (loss_percent>0 && 100*((float)rand())/RAND_MAX<loss_percent) lost=1; /*End of stream condition*/ if (op.e_o_s && os.serialno == speex_serialno) /* don't care for anything except speex eos */ eos=1; /*Copy Ogg packet to Speex bitstream*/...