 |
libdspl-2.0
Digital Signal Processing Algorithm Library
|
27 #include "dspl_internal.h"
32 #ifdef DOXYGEN_ENGLISH
76 #ifdef DOXYGEN_RUSSIAN
130 case RAND_TYPE_MRG32K3A:
138 prnd->
mrg32k3a_x[2] = (double) rand() * rand();
140 case RAND_TYPE_MT19937:
142 mt19937_init_genrand64(*((
unsigned long long*)seed), prnd);
144 mt19937_init_genrand64((
unsigned long long)rand()*rand(), prnd);
157 #ifdef DOXYGEN_ENGLISH
200 #ifdef DOXYGEN_RUSSIAN
246 double z[RAND_BUFSIZE];
255 i = cnt % RAND_BUFSIZE;
258 err = randu(z, RAND_BUFSIZE, prnd);
262 x[cnt] = z[i] > 0.5 ? 1.0 : 0.0;
271 #ifdef DOXYGEN_ENGLISH
314 #ifdef DOXYGEN_RUSSIAN
360 double z[RAND_BUFSIZE];
369 i = cnt % RAND_BUFSIZE;
372 err = randu(z, RAND_BUFSIZE, prnd);
376 x[cnt] = z[i] > 0.5 ? 1.0 : -1.0;
385 #ifdef DOXYGEN_ENGLISH
388 #ifdef DOXYGEN_RUSSIAN
391 int randu_mrg32k3a (
double* u,
int n,
random_t* prnd)
400 double xn, yn, *x, *y;
405 for(k = 0; k < n; k++)
408 xn = MRG32K3A_A12 * x[1] - MRG32K3A_A13 * x[2];
410 z = (long)(xn / MRG32K3A_M1);
411 xn -= (double)z * MRG32K3A_M1;
420 yn = MRG32K3A_A21 * y[0] - MRG32K3A_A23 * y[2];
421 z = (long)(yn / MRG32K3A_M2);
422 yn -= (double)z * MRG32K3A_M2;
431 u[k] = (xn <= yn) ? ((xn - yn + MRG32K3A_M1) * MRG32K3A_NORM):
432 (xn - yn) * MRG32K3A_NORM;
444 #ifdef DOXYGEN_ENGLISH
447 #ifdef DOXYGEN_RUSSIAN
498 int DSPL_API randi(
int* x,
int n,
int start,
int stop,
random_t* prnd)
500 double z[RAND_BUFSIZE];
508 dx = (double)stop - (
double)start;
512 i = cnt % RAND_BUFSIZE;
515 err = randu(z, RAND_BUFSIZE, prnd);
519 x[cnt] = start + (int)round(z[i] * dx);
531 #ifdef DOXYGEN_ENGLISH
534 #ifdef DOXYGEN_RUSSIAN
589 int DSPL_API randn(
double* x,
int n,
double mu,
double sigma,
random_t* prnd)
592 double x1[RAND_BUFSIZE], x2[RAND_BUFSIZE];
606 if((res = randu(x1, RAND_BUFSIZE, prnd)) !=
RES_OK)
608 if((res = randu(x2, RAND_BUFSIZE, prnd)) !=
RES_OK)
611 while(k < n && m < RAND_BUFSIZE)
615 x[k] = sqrt(-2.0*log(x1[m]))*cos(M_2PI*x2[m])*sigma + mu;
630 #ifdef DOXYGEN_ENGLISH
633 #ifdef DOXYGEN_RUSSIAN
641 err = randn((
double*)x, 2*n, 0.0, sigma / M_SQRT2, prnd);
646 for(i = 0; i < n; i++)
648 RE(x[i]) +=
RE(mu[0]);
649 IM(x[i]) +=
IM(mu[0]);
660 #ifdef DOXYGEN_ENGLISH
663 #ifdef DOXYGEN_RUSSIAN
727 int DSPL_API randu(
double* x,
int n,
random_t* prnd)
740 case RAND_TYPE_MRG32K3A:
741 return randu_mrg32k3a(x, n, prnd);
742 case RAND_TYPE_MT19937:
743 for(i = 0; i < n; i++)
744 x[i] = mt19937_genrand64_real1(prnd);
756 for(i = 0; i < n; i++)
757 x[i] = (
double)rand()/RAND_MAX;
#define RE(x)
Macro sets real part of the complex number.
#define ERROR_PTR
Pointer error. This error means that one of the required pointers (memory to be allocated for) is tra...
#define ERROR_SIZE
Error array size. This error occurs when in addition to the pointer the wrong input is passed to the ...
#define ERROR_RAND_TYPE
Unknown pseudorandom number genration algorithm. The following algorithms are used in the library:
int DSPL_API random_init(random_t *prnd, int type, void *seed)
Pseudorandom numbers generators initialization.
int DSPL_API randb(double *x, int n, random_t *prnd)
Binary unipolar [0, 1] pseudorandom vector.
double complex_t[2]
Complex data type.
#define RES_OK
The function completed correctly. No errors.
#define IM(x)
Macro sets imaginary part of the complex number.
#define ERROR_RAND_SIGMA
The standard deviation is incorrect normal distribution of a random variable. The standard deviation ...
int DSPL_API randb2(double *x, int n, random_t *prnd)
Binary bipolar [-1, 1] pseudorandom vector.