random number generation organized

This commit is contained in:
h_vogt 2008-11-29 20:21:56 +00:00
parent 30f1a881f3
commit e7fe33ece8
7 changed files with 52 additions and 85 deletions

View File

@ -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
* 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 -

View File

@ -10,15 +10,8 @@
#include "numparam.h"
#include "ngspice.h"
/* MINGW: random in libiberty.a, but not in libiberty.h */
#if defined(__MINGW32__) && defined(HAVE_RANDOM)
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
/* random numbers in /maths/misc/randnumb.c */
extern double gauss();
/************ keywords ************/
@ -27,19 +20,6 @@ static Str (150, keys); /* all my keywords */
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
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
agauss (double nominal_val, double variation, double sigma)
{

View File

@ -153,6 +153,9 @@ struct timeb timebegin;
#ifndef HAVE_RANDOM
#define srandom(a) srand(a)
#define random rand
#define RR_MAX RAND_MAX
#else
#define RR_MAX LONG_MAX
#endif
#ifdef HAVE_INDEX

View File

@ -30,6 +30,8 @@ extern long int random (void);
extern void srandom (unsigned int seed);
#endif
extern void checkseed(); /* seed random or set by 'set rndseed=value'*/
static double *
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, ...)
{
*newlength = length;
checkseed();
if (type == VF_COMPLEX) {
complex *c;
complex *cc = (complex *) data;
int i;
complex *c;
complex *cc = (complex *) data;
int i;
c = alloc_c(length);
*newtype = VF_COMPLEX;
for (i = 0; i < length; i++) {
int j, k;
j = (int)floor(realpart(&cc[i]));
k = (int)floor(imagpart(&cc[i]));
realpart(&c[i]) = j ? random() % j : 0;
imagpart(&c[i]) = k ? random() % k : 0;
}
return ((void *) c);
c = alloc_c(length);
*newtype = VF_COMPLEX;
for (i = 0; i < length; i++) {
int j, k;
j = (int)floor(realpart(&cc[i]));
k = (int)floor(imagpart(&cc[i]));
realpart(&c[i]) = j ? random() % j : 0;
imagpart(&c[i]) = k ? random() % k : 0;
}
return ((void *) c);
} else {
double *d;
double *dd = (double *) data;
int i;
double *d;
double *dd = (double *) data;
int i;
d = alloc_d(length);
*newtype = VF_REAL;
for (i = 0; i < length; i++) {
int j;
d = alloc_d(length);
*newtype = VF_REAL;
for (i = 0; i < length; i++) {
int j;
j = (int)floor(dd[i]);
d[i] = j ? random() % j : 0;
}
return ((void *) d);
j = (int)floor(dd[i]);
d[i] = j ? random() % j : 0;
}
return ((void *) d);
}
}
/* Compute the mean of a vector. */

View File

@ -13,7 +13,8 @@ libmathmisc_la_SOURCES = \
logb.c \
scalb.c \
norm.h \
norm.c
norm.c \
randnumb.c
AM_CPPFLAGS = -I$(top_srcdir)/src/include

View File

@ -1,7 +1,9 @@
* Standard spice and nutmeg init file
* Standard ngspice init file
alias exit quit
alias acct rusage all
set x11lineararcs
*set rndseed=12
*set filetype=ascii
*unset brief
@ -11,7 +13,7 @@ if $__flag = 0
*set numparams
* 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
* The other codemodels

View File

@ -48,7 +48,7 @@
RuntimeTypeInfo="false"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
CompileAs="1"
/>
@ -1100,11 +1100,11 @@
>
</File>
<File
RelativePath="..\src\frontend\plotting\grid.h"
RelativePath="..\src\include\grid.h"
>
</File>
<File
RelativePath="..\src\include\grid.h"
RelativePath="..\src\frontend\plotting\grid.h"
>
</File>
<File
@ -7191,6 +7191,10 @@
RelativePath="..\src\frontend\quote.c"
>
</File>
<File
RelativePath="..\src\maths\misc\randnumb.c"
>
</File>
<File
RelativePath="..\src\frontend\rawfile.c"
>