libdspl-2.0
Digital Signal Processing Algorithm Library
|
Functions | |
int DSPL_API | randb (double *x, int n, random_t *prnd) |
Binary unipolar [0, 1] pseudorandom vector. More... | |
int DSPL_API | randb2 (double *x, int n, random_t *prnd) |
Binary bipolar [-1, 1] pseudorandom vector. More... | |
int DSPL_API | random_init (random_t *prnd, int type, void *seed) |
Pseudorandom numbers generators initialization. More... | |
Detailed Description
This group describes the functions of the pseudo-random numbers generation by different algorithms.
Function Documentation
◆ randb()
int randb | ( | double * | x, |
int | n, | ||
random_t * | prnd | ||
) |
Binary unipolar [0, 1] pseudorandom vector.
The function generates a unipolar pseudo-random vector, each element of which takes an equally probable value of 0 or 1
- Parameters
-
[in,out] x
Pointer to the unipolar pseudo-random vector.
Vector size is[n x 1]
.
Memory must be allocated.
[in] n Size of vector x
.
[in] prnd Pointer to the random_t
structure.
The structure must be pre-filled with the random_init function.
This pointer can beNULL
, then it will be used built-in pseudorandom generator defined by the C language standard. However, this mode is not recommended, for example in cryptography and other tasks. There is no guarantee of the quality of the pseudorandom numbers produced if theprnd
parameter is set toNULL
.
- Returns
RES_OK
— if pseudorandom vector is calculated successfully.
Else code error.
Example:
Program genrates unipolar [0, 1] and bipolar[-1, 1] pseudorandom binary vectors.
As a result of the program run, you can see the graph:
◆ randb2()
int randb2 | ( | double * | x, |
int | n, | ||
random_t * | prnd | ||
) |
Binary bipolar [-1, 1] pseudorandom vector.
The function generates a unipolar pseudo-random vector, each element of which takes an equally probable value of -1 or 1
- Parameters
-
[in,out] x
Pointer to the bipolar pseudorandom vector.
Vector size is[n x 1]
.
Memory must be allocated.
[in] n Size of vector x
.
[in] prnd Pointer to the random_t
structure.
The structure must be pre-filled with the random_init function.
This pointer can beNULL
, then it will be used built-in pseudorandom generator defined by the C language standard. However, this mode is not recommended, for example in cryptography and other tasks. There is no guarantee of the quality of the pseudorandom numbers produced if theprnd
parameter is set toNULL
.
- Returns
RES_OK
— if pseudorandom vector is calculated successfully.
Else code error.
Example:
Program genrates unipolar [0, 1] and bipolar[-1, 1] pseudorandom binary vectors.
As a result of the program run, you can see the graph:
◆ random_init()
int random_init | ( | random_t * | prnd, |
int | type, | ||
void * | seed | ||
) |
Pseudorandom numbers generators initialization.
- Parameters
-
[in,out] prnd Pointer to the pseudorandom generators parameters and state vectors.
[in] type Pseudorandom generator algorithm: RAND_TYPE_MRG32K3A - 32-bits MRG32K3A generator RAND_TYPE_MT19937 - 64-bits MT19937-64 generator
[in] seed Pointer to the generator start initialization.
Type of this pointer isvoid*
because different generators are using different initial values. For example, if we initialize the MRG32K3A generator, then thetype
parameter is specified asRAND_TYPE_MRG32K3A
, andseed
converts todouble
pointer: For 64-bits Mersenne Twister pseudorandom number generator (type
sets asRAND_TYPE_MT19937
),seed
converts to theunsigned long long
pointer:Pseudorandom numbers will be repeated each program restart ifrandom_t rnd = {0};unsigned long long seed = 1234353456;random_init(&rnd, RAND_TYPE_MT19937, (void*)&seed);seed
value is the same.
Theseed
pointer can beNULL
. Pseudorandom generators will be initialized by pseudorandom numbers in this case and program will generate different pseudorandom numbers each restart.
Definition at line 120 of file random_init.c.
Generated on Wed Jan 5 2022 12:44:37 for libdspl-2.0 by 1.9.2