/*
* Copyright (c) 2015-2019 Sergey Bakhurin
* Digital Signal Processing Library [http://dsplib.org]
*
* This file is part of libdspl-2.0.
*
* is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DSPL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Foobar. If not, see .
*/
#include
#include
#include
#include "dspl.h"
#include "dspl_internal.h"
/******************************************************************************
Uniform random numbers generator
*******************************************************************************/
int DSPL_API randu(double* x, int n)
{
int k,m;
unsigned int x1[4], x2[4], y;
if(!x)
return ERROR_PTR;
if(n<1)
return ERROR_SIZE;
x1[1] = rand();
x2[1] = rand();
x1[2] = rand();
x2[2] = rand();
x1[3] = rand();
x2[3] = rand();
for(k = 0; k 0; m--)
{
x1[m] = x1[m-1];
x2[m] = x2[m-1];
}
x[k] = (double)y/DSPL_RAND_MOD_X1;
}
return RES_OK;
}
/*******************************************************************************
Gaussian random numbers generator
*******************************************************************************/
int DSPL_API randn(double* x, int n, double mu, double sigma)
{
int k, m;
double x1[128], x2[128];
int res;
if(!x)
return ERROR_PTR;
if(n<1)
return ERROR_SIZE;
if(sigma < 0.0)
return ERROR_RAND_SIGMA;
k=0;
while(k < n)
{
res = randu(x1, 128);
if(res != RES_OK)
goto exit_label;
res = randu(x2, 128);
if(res != RES_OK)
goto exit_label;
m = 0 ;
while(k