random number generation organized
This commit is contained in:
parent
30f1a881f3
commit
e7fe33ece8
|
|
@ -1,3 +1,10 @@
|
||||||
|
2008-11-29 Holger Vogt
|
||||||
|
* frontend/numparam/xpressn.c: rand() and gauss() moved to
|
||||||
|
math/misc/randnumb.c
|
||||||
|
* 'set rndseed=value' value = integer > 0 in spinit will yield
|
||||||
|
deterministic pseudo random number sequence.
|
||||||
|
* random() and rand() with correspongding max value
|
||||||
|
|
||||||
2008-11-26 Dietmar Warning
|
2008-11-26 Dietmar Warning
|
||||||
* src/spicelib/devices/bsim4v4, bsim4v5: this is a backup because the patch of
|
* src/spicelib/devices/bsim4v4, bsim4v5: this is a backup because the patch of
|
||||||
Phil Barker are providing only a placeholder for propriarity sti stress model -
|
Phil Barker are providing only a placeholder for propriarity sti stress model -
|
||||||
|
|
|
||||||
|
|
@ -10,15 +10,8 @@
|
||||||
#include "numparam.h"
|
#include "numparam.h"
|
||||||
#include "ngspice.h"
|
#include "ngspice.h"
|
||||||
|
|
||||||
/* MINGW: random in libiberty.a, but not in libiberty.h */
|
/* random numbers in /maths/misc/randnumb.c */
|
||||||
#if defined(__MINGW32__) && defined(HAVE_RANDOM)
|
extern double gauss();
|
||||||
extern long int random (void);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* agauss added by Stephan Thiel June 2008 */
|
|
||||||
#define Rand_Call random
|
|
||||||
#define Rand_Seed srandom
|
|
||||||
#define Rand_Range 1073741824
|
|
||||||
|
|
||||||
/************ keywords ************/
|
/************ keywords ************/
|
||||||
|
|
||||||
|
|
@ -27,19 +20,6 @@ static Str (150, keys); /* all my keywords */
|
||||||
static Str (150, fmath); /* all math functions */
|
static Str (150, fmath); /* all math functions */
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
static double
|
|
||||||
max (double x, double y)
|
|
||||||
{
|
|
||||||
return (x > y) ? x : y;
|
|
||||||
}
|
|
||||||
|
|
||||||
static double
|
|
||||||
min (double x, double y)
|
|
||||||
{
|
|
||||||
return (x < y) ? x : y;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
static double
|
static double
|
||||||
ternary_fcn (int conditional, double if_value, double else_value)
|
ternary_fcn (int conditional, double if_value, double else_value)
|
||||||
{
|
{
|
||||||
|
|
@ -50,38 +30,6 @@ ternary_fcn (int conditional, double if_value, double else_value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
double drand()
|
|
||||||
{
|
|
||||||
/* uniform random number generator, interval -1 .. +1 */
|
|
||||||
return ( 2.0*((double) (RAND_MAX-abs(Rand_Call())) / (double)RAND_MAX-0.5));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*** gauss ***/
|
|
||||||
|
|
||||||
double gauss()
|
|
||||||
{
|
|
||||||
static bool gliset = TRUE;
|
|
||||||
static double glgset = 0.0;
|
|
||||||
double fac,r,v1,v2;
|
|
||||||
if (gliset) {
|
|
||||||
do {
|
|
||||||
v1 = drand(); v2 = drand();
|
|
||||||
r = v1*v1 + v2*v2;
|
|
||||||
} while (r >= 1.0);
|
|
||||||
fac = sqrt(-2.0 * log(r) / r);
|
|
||||||
glgset = v1 * fac;
|
|
||||||
gliset = FALSE;
|
|
||||||
return v2 * fac;
|
|
||||||
} else {
|
|
||||||
gliset = TRUE;
|
|
||||||
return glgset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static double
|
static double
|
||||||
agauss (double nominal_val, double variation, double sigma)
|
agauss (double nominal_val, double variation, double sigma)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,9 @@ struct timeb timebegin;
|
||||||
#ifndef HAVE_RANDOM
|
#ifndef HAVE_RANDOM
|
||||||
#define srandom(a) srand(a)
|
#define srandom(a) srand(a)
|
||||||
#define random rand
|
#define random rand
|
||||||
|
#define RR_MAX RAND_MAX
|
||||||
|
#else
|
||||||
|
#define RR_MAX LONG_MAX
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_INDEX
|
#ifdef HAVE_INDEX
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ extern long int random (void);
|
||||||
extern void srandom (unsigned int seed);
|
extern void srandom (unsigned int seed);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern void checkseed(); /* seed random or set by 'set rndseed=value'*/
|
||||||
|
|
||||||
static double *
|
static double *
|
||||||
d_tan(double *dd, int length)
|
d_tan(double *dd, int length)
|
||||||
{
|
{
|
||||||
|
|
@ -209,37 +211,37 @@ void *
|
||||||
cx_rnd(void *data, short int type, int length, int *newlength, short int *newtype, ...)
|
cx_rnd(void *data, short int type, int length, int *newlength, short int *newtype, ...)
|
||||||
{
|
{
|
||||||
*newlength = length;
|
*newlength = length;
|
||||||
|
checkseed();
|
||||||
if (type == VF_COMPLEX) {
|
if (type == VF_COMPLEX) {
|
||||||
complex *c;
|
complex *c;
|
||||||
complex *cc = (complex *) data;
|
complex *cc = (complex *) data;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
c = alloc_c(length);
|
c = alloc_c(length);
|
||||||
*newtype = VF_COMPLEX;
|
*newtype = VF_COMPLEX;
|
||||||
for (i = 0; i < length; i++) {
|
for (i = 0; i < length; i++) {
|
||||||
int j, k;
|
int j, k;
|
||||||
|
j = (int)floor(realpart(&cc[i]));
|
||||||
j = (int)floor(realpart(&cc[i]));
|
k = (int)floor(imagpart(&cc[i]));
|
||||||
k = (int)floor(imagpart(&cc[i]));
|
realpart(&c[i]) = j ? random() % j : 0;
|
||||||
realpart(&c[i]) = j ? random() % j : 0;
|
imagpart(&c[i]) = k ? random() % k : 0;
|
||||||
imagpart(&c[i]) = k ? random() % k : 0;
|
}
|
||||||
}
|
return ((void *) c);
|
||||||
return ((void *) c);
|
|
||||||
} else {
|
} else {
|
||||||
double *d;
|
double *d;
|
||||||
double *dd = (double *) data;
|
double *dd = (double *) data;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
d = alloc_d(length);
|
d = alloc_d(length);
|
||||||
*newtype = VF_REAL;
|
*newtype = VF_REAL;
|
||||||
for (i = 0; i < length; i++) {
|
for (i = 0; i < length; i++) {
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
j = (int)floor(dd[i]);
|
j = (int)floor(dd[i]);
|
||||||
d[i] = j ? random() % j : 0;
|
d[i] = j ? random() % j : 0;
|
||||||
}
|
|
||||||
return ((void *) d);
|
|
||||||
}
|
}
|
||||||
|
return ((void *) d);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compute the mean of a vector. */
|
/* Compute the mean of a vector. */
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@ libmathmisc_la_SOURCES = \
|
||||||
logb.c \
|
logb.c \
|
||||||
scalb.c \
|
scalb.c \
|
||||||
norm.h \
|
norm.h \
|
||||||
norm.c
|
norm.c \
|
||||||
|
randnumb.c
|
||||||
|
|
||||||
AM_CPPFLAGS = -I$(top_srcdir)/src/include
|
AM_CPPFLAGS = -I$(top_srcdir)/src/include
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
* Standard spice and nutmeg init file
|
* Standard ngspice init file
|
||||||
alias exit quit
|
alias exit quit
|
||||||
alias acct rusage all
|
alias acct rusage all
|
||||||
set x11lineararcs
|
set x11lineararcs
|
||||||
|
*set rndseed=12
|
||||||
|
*set filetype=ascii
|
||||||
|
|
||||||
*unset brief
|
*unset brief
|
||||||
|
|
||||||
|
|
@ -11,7 +13,7 @@ if $__flag = 0
|
||||||
*set numparams
|
*set numparams
|
||||||
|
|
||||||
* For SPICE2 POLYs, edit the below line to point to the location
|
* For SPICE2 POLYs, edit the below line to point to the location
|
||||||
* of your codemode.
|
* of your codemodel.
|
||||||
@XSPICEINIT@ codemodel @prefix@/lib/spice/spice2poly.cm
|
@XSPICEINIT@ codemodel @prefix@/lib/spice/spice2poly.cm
|
||||||
|
|
||||||
* The other codemodels
|
* The other codemodels
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@
|
||||||
RuntimeTypeInfo="false"
|
RuntimeTypeInfo="false"
|
||||||
UsePrecompiledHeader="0"
|
UsePrecompiledHeader="0"
|
||||||
WarningLevel="3"
|
WarningLevel="3"
|
||||||
Detect64BitPortabilityProblems="true"
|
Detect64BitPortabilityProblems="false"
|
||||||
DebugInformationFormat="4"
|
DebugInformationFormat="4"
|
||||||
CompileAs="1"
|
CompileAs="1"
|
||||||
/>
|
/>
|
||||||
|
|
@ -1100,11 +1100,11 @@
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\src\frontend\plotting\grid.h"
|
RelativePath="..\src\include\grid.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\src\include\grid.h"
|
RelativePath="..\src\frontend\plotting\grid.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
|
|
@ -7191,6 +7191,10 @@
|
||||||
RelativePath="..\src\frontend\quote.c"
|
RelativePath="..\src\frontend\quote.c"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\src\maths\misc\randnumb.c"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\src\frontend\rawfile.c"
|
RelativePath="..\src\frontend\rawfile.c"
|
||||||
>
|
>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue