libdspl-2.0
Библиотека алгоритмов цифровой обработки сигналов
randu.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 
32 
33 
34 
35 
36 #ifdef DOXYGEN_ENGLISH
37 
38 #endif
39 #ifdef DOXYGEN_RUSSIAN
40 
102 #endif
103 int DSPL_API randu(double* x, int n, random_t* prnd)
104 {
105  int i;
106 
107  if(!x)
108  return ERROR_PTR;
109  if(n < 0)
110  return ERROR_SIZE;
111 
112  if(prnd)
113  {
114  switch(prnd->type)
115  {
116  case RAND_TYPE_MRG32K3A:
117  return randu_mrg32k3a(x, n, prnd);
118  case RAND_TYPE_MT19937:
119  for(i = 0; i < n; i++)
120  x[i] = mt19937_genrand64_real1(prnd);
121  return RES_OK;
122  default:
123  return ERROR_RAND_TYPE;
124  }
125  }
126  else
127  {
128  if(!x)
129  return ERROR_PTR;
130  if(n<1)
131  return ERROR_SIZE;
132  for(i = 0; i < n; i++)
133  x[i] = (double)rand()/RAND_MAX;
134  }
135 
136  return RES_OK;
137 }
138 
Структура параметров датчиков псевдослучайных чисел.
Definition: dspl.h:349
#define ERROR_PTR
Ошибка указателя. Данная ошибка означает, что один из обязательных указателей (память под который дол...
Definition: dspl.h:610
#define ERROR_SIZE
Ошибка при передаче размера массива. Данная ошибка возникает когда помимо указателя на массив входных...
Definition: dspl.h:618
int type
Definition: dspl.h:360
#define ERROR_RAND_TYPE
Неизвестный датчик псевдослучайных чисел. В библиотеке используются следующие датчики:
Definition: dspl.h:614
int randu(double *x, int n, random_t *prnd)
Генерация вектора равномерно-распределенных в интервале от 0 до 1 псевдослучайных чисел.
Definition: randu.c:103
#define RES_OK
Функция завершилась корректно. Ошибки отсутствуют.
Definition: dspl.h:558