ranl1.c

来自「包含有各种各样的数字信号处理经典算法源代码,很有用的.」· C语言 代码 · 共 27 行

C
27
字号
/* ranl.c - linearly interpolated random generator of period D */double ran();                             /* uniform generator */void cdelay2();                           /* circular delay */double ranl(D, u, q, iseed)               /* usage: y = ranl(D, u, &q, &iseed); */int D, *q;                                /* \(q\) is cycled modulo-\(D\) */double *u;                                /* \(u\) = 2-dimensional array */long *iseed;                              /* \(q\), iseed are passed by address */{       double y;       int i;       i = (D - *q) % D;                      /* interpolation index */       y = u[0] + (u[1] - u[0]) * i / D;      /* linear interpolation */       cdelay2(D-1, q);                       /* decrement \(q\) and wrap mod-\(D\) */       if (*q == 0) {                         /* every \(D\) calls, */              u[0] = u[1];                    /* set new \(u[0]\) and */              u[1] = ran(iseed) - 0.5;        /* get new \(u[1]\) (zero mean) */              }       return y;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?