diff options
author | siddhu8990 | 2016-02-01 11:29:45 +0530 |
---|---|---|
committer | siddhu8990 | 2016-02-01 11:29:45 +0530 |
commit | bbdc94252ee563f0b01d4949868a583e43a2e6a8 (patch) | |
tree | 5f5197d22bba24e41928c98aed936dc5ad828fcf /src/c/auxiliaryFunctions/rand/i16rands.c | |
parent | 5df6d1cb2868abdc8df66755f76c997ee36c0b49 (diff) | |
parent | 8ee41aca4183a0239b9cb220de3f159b1f0910fb (diff) | |
download | Scilab2C_fossee_old-bbdc94252ee563f0b01d4949868a583e43a2e6a8.tar.gz Scilab2C_fossee_old-bbdc94252ee563f0b01d4949868a583e43a2e6a8.tar.bz2 Scilab2C_fossee_old-bbdc94252ee563f0b01d4949868a583e43a2e6a8.zip |
Merged RPi and bit operators
Diffstat (limited to 'src/c/auxiliaryFunctions/rand/i16rands.c')
-rw-r--r-- | src/c/auxiliaryFunctions/rand/i16rands.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/c/auxiliaryFunctions/rand/i16rands.c b/src/c/auxiliaryFunctions/rand/i16rands.c new file mode 100644 index 0000000..ca2ed9c --- /dev/null +++ b/src/c/auxiliaryFunctions/rand/i16rands.c @@ -0,0 +1,46 @@ +/* Scilab2C FOSSEE IIT Bombay */ +#include "rand.h" +#include <stdio.h> + +double i16rands(void) +{ + +int m=1; +const int itwo=2; +static int m2=0,halfm=0,ia=0,ic=0,mic=0,iy=0; +static double s=0.0; +if(m2==0) +{ + /*if first entry,compute machine integer word length*/ + while(m>m2) + { + m2=m; + m=itwo*m2; + } + halfm = m2; + /* compute multiplier and increment for linear congruential methos */ + ia = 8*(int)(halfm*atan(1.0)/8.0) + 5; + ic = 2*(int)(halfm*(0.5-sqrt(3.0)/6.0)) +1; + mic = (m2 - ic) + m2; + /* s is the scale factor for converting to floating point*/ + s = 0.5/halfm; + +} + +/* compute next random number */ + iy = iy*ia; +/* the following statement is for computers which do not allow interger overflow on addition*/ +if(iy > mic) iy = (iy - m2) - m2; + iy = iy + ic; + + /* the following statement is for computers where the word length for addition is greater than for multiplication */ + if(iy/2 > m2) iy = (iy - m2) - m2; + /* the following statement is for computers where integer overflow affects the sign bit */ + if(iy < 0) iy = (iy + m2) + m2; + return (double)iy*s; + + + + + +} |