2012-05-22 13:09:48 -04:00
|
|
|
#include "getfile.h"
|
2020-06-13 11:04:41 -04:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
|
|
|
#include <QRandomGenerator>
|
|
|
|
#include <random>
|
|
|
|
#endif
|
2021-06-10 10:23:48 -04:00
|
|
|
|
2012-05-22 13:09:48 -04:00
|
|
|
#include <stdlib.h>
|
2016-01-02 09:29:02 -05:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
2012-05-22 13:09:48 -04:00
|
|
|
#include <math.h>
|
2012-11-16 10:57:42 -05:00
|
|
|
|
|
|
|
#ifdef WIN32
|
2012-10-28 11:47:43 -04:00
|
|
|
#include <windows.h>
|
2013-07-08 09:17:22 -04:00
|
|
|
#else
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <err.h>
|
2012-11-16 10:57:42 -05:00
|
|
|
#endif
|
2012-05-22 13:09:48 -04:00
|
|
|
|
|
|
|
//#define MAX_RANDOM 0x7fffffff
|
|
|
|
/* Generate gaussian random float with mean=0 and std_dev=1 */
|
|
|
|
float gran()
|
|
|
|
{
|
2020-06-13 11:04:41 -04:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
|
|
|
static std::normal_distribution<float> d;
|
|
|
|
return d (*QRandomGenerator::global ());
|
|
|
|
#else
|
2012-05-22 13:09:48 -04:00
|
|
|
float fac,rsq,v1,v2;
|
|
|
|
static float gset;
|
|
|
|
static int iset;
|
|
|
|
|
|
|
|
if(iset){
|
|
|
|
/* Already got one */
|
|
|
|
iset = 0;
|
|
|
|
return gset;
|
|
|
|
}
|
|
|
|
/* Generate two evenly distributed numbers between -1 and +1
|
|
|
|
* that are inside the unit circle
|
|
|
|
*/
|
|
|
|
do {
|
2015-07-12 06:28:28 -04:00
|
|
|
v1 = 2.0 * (float)qrand() / RAND_MAX - 1;
|
|
|
|
v2 = 2.0 * (float)qrand() / RAND_MAX - 1;
|
2012-05-22 13:09:48 -04:00
|
|
|
rsq = v1*v1 + v2*v2;
|
|
|
|
} while(rsq >= 1.0 || rsq == 0.0);
|
|
|
|
fac = sqrt(-2.0*log(rsq)/rsq);
|
|
|
|
gset = v1*fac;
|
|
|
|
iset++;
|
|
|
|
return v2*fac;
|
2020-06-13 11:04:41 -04:00
|
|
|
#endif
|
2012-05-22 13:09:48 -04:00
|
|
|
}
|