libdspl-2.0
Библиотека алгоритмов цифровой обработки сигналов
randb.c
1 /*
2 * Copyright (c) 2015-2024 Sergey Bakhurin
3 * Digital Signal Processing Library [http://dsplib.org]
4 *
5 * This file is part of libdspl-2.0.
6 *
7 * is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * DSPL is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 
22 #include <stdlib.h>
23 #include <math.h>
24 #include <time.h>
25 
26 #include "dspl.h"
27 #include "randomgen.h"
28 
29 
30 
31 #ifdef DOXYGEN_ENGLISH
32 
73 #endif
74 #ifdef DOXYGEN_RUSSIAN
75 
117 #endif
118 int DSPL_API randb(double* x, int n, random_t* prnd)
119 {
120  double z[RAND_BUFSIZE];
121  int i, cnt, err;
122  if(!x)
123  return ERROR_PTR;
124  if(n < 1)
125  return ERROR_SIZE;
126  cnt = 0;
127  while(cnt < n)
128  {
129  i = cnt % RAND_BUFSIZE;
130  if(!i)
131  {
132  err = randu(z, RAND_BUFSIZE, prnd);
133  if(err != RES_OK)
134  return err;
135  }
136  x[cnt] = z[i] > 0.5 ? 1.0 : 0.0;
137  cnt++;
138  }
139  return RES_OK;
140 }
141 
Структура параметров датчиков псевдослучайных чисел.
Definition: dspl.h:349
#define ERROR_PTR
Ошибка указателя. Данная ошибка означает, что один из обязательных указателей (память под который дол...
Definition: dspl.h:610
#define ERROR_SIZE
Ошибка при передаче размера массива. Данная ошибка возникает когда помимо указателя на массив входных...
Definition: dspl.h:618
int randu(double *x, int n, random_t *prnd)
Генерация вектора равномерно-распределенных в интервале от 0 до 1 псевдослучайных чисел.
Definition: randu.c:103
int randb(double *x, int n, random_t *prnd)
Генерация бинарного униполярного [0, 1] псевдослучайного вектора
Definition: randb.c:118
#define RES_OK
Функция завершилась корректно. Ошибки отсутствуют.
Definition: dspl.h:558