diff --git a/ChangeLog b/ChangeLog
index 0981916bc..75fa31d13 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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 -
diff --git a/src/frontend/numparam/xpressn.c b/src/frontend/numparam/xpressn.c
index 760818e7e..c9f7cec45 100644
--- a/src/frontend/numparam/xpressn.c
+++ b/src/frontend/numparam/xpressn.c
@@ -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)
{
diff --git a/src/include/ngspice.h b/src/include/ngspice.h
index 99ad99386..ef43c2a2c 100644
--- a/src/include/ngspice.h
+++ b/src/include/ngspice.h
@@ -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
diff --git a/src/maths/cmaths/cmath2.c b/src/maths/cmaths/cmath2.c
index f2bf4b963..67cd6b838 100644
--- a/src/maths/cmaths/cmath2.c
+++ b/src/maths/cmaths/cmath2.c
@@ -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. */
diff --git a/src/maths/misc/Makefile.am b/src/maths/misc/Makefile.am
index 8ff3c274c..f3b4087a0 100644
--- a/src/maths/misc/Makefile.am
+++ b/src/maths/misc/Makefile.am
@@ -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
diff --git a/src/spinit.in b/src/spinit.in
index 1bb14c445..9af9047f1 100644
--- a/src/spinit.in
+++ b/src/spinit.in
@@ -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
diff --git a/visualc/vngspice.vcproj b/visualc/vngspice.vcproj
index 576005ced..63aec42a6 100644
--- a/visualc/vngspice.vcproj
+++ b/visualc/vngspice.vcproj
@@ -48,7 +48,7 @@
RuntimeTypeInfo="false"
UsePrecompiledHeader="0"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
+ Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
CompileAs="1"
/>
@@ -1100,11 +1100,11 @@
>
+
+