randnumb.c, main.c, sharedspice.c,spinit.in
replace 'set seed = val' by 'setseed val' no more check_seed in every random number calculation
This commit is contained in:
parent
4e04f1f17c
commit
310efd1307
|
|
@ -887,9 +887,10 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
cp_program = ft_sim->simulator;
|
cp_program = ft_sim->simulator;
|
||||||
|
|
||||||
int ii = getpid();
|
/* initialze random number generator with seed = 1 */
|
||||||
|
int ii = 1;
|
||||||
cp_vset("rndseed", CP_NUM, &ii);
|
cp_vset("rndseed", CP_NUM, &ii);
|
||||||
checkseed();
|
com_sseed(NULL);
|
||||||
|
|
||||||
/* --- Process command line options --- */
|
/* --- Process command line options --- */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,6 @@ void checkseed(void)
|
||||||
/* uniform random number generator, interval [-1 .. +1[ */
|
/* uniform random number generator, interval [-1 .. +1[ */
|
||||||
double drand(void)
|
double drand(void)
|
||||||
{
|
{
|
||||||
checkseed();
|
|
||||||
// return ( 2.0*((double) (RR_MAX-abs(rand())) / (double)RR_MAX-0.5));
|
// return ( 2.0*((double) (RR_MAX-abs(rand())) / (double)RR_MAX-0.5));
|
||||||
return 2.0 * CombLCGTaus() - 1.0;
|
return 2.0 * CombLCGTaus() - 1.0;
|
||||||
}
|
}
|
||||||
|
|
@ -205,7 +204,6 @@ double gauss0(void)
|
||||||
static double glgset = 0.0;
|
static double glgset = 0.0;
|
||||||
double fac,r,v1,v2;
|
double fac,r,v1,v2;
|
||||||
if (gliset) {
|
if (gliset) {
|
||||||
checkseed();
|
|
||||||
do {
|
do {
|
||||||
v1 = 2.0 * CombLCGTaus() - 1.0;
|
v1 = 2.0 * CombLCGTaus() - 1.0;
|
||||||
v2 = 2.0 * CombLCGTaus() - 1.0;
|
v2 = 2.0 * CombLCGTaus() - 1.0;
|
||||||
|
|
@ -228,7 +226,6 @@ double gauss0(void)
|
||||||
double gauss1(void)
|
double gauss1(void)
|
||||||
{
|
{
|
||||||
double fac, r, v1, v2;
|
double fac, r, v1, v2;
|
||||||
checkseed();
|
|
||||||
do {
|
do {
|
||||||
v1 = 2.0 * CombLCGTaus() - 1.0;
|
v1 = 2.0 * CombLCGTaus() - 1.0;
|
||||||
v2 = 2.0 * CombLCGTaus() - 1.0;
|
v2 = 2.0 * CombLCGTaus() - 1.0;
|
||||||
|
|
@ -249,7 +246,6 @@ double gauss1(void)
|
||||||
void rgauss(double* py1, double* py2)
|
void rgauss(double* py1, double* py2)
|
||||||
{
|
{
|
||||||
double x1, x2, w;
|
double x1, x2, w;
|
||||||
checkseed();
|
|
||||||
do {
|
do {
|
||||||
x1 = 2.0 * CombLCGTaus() - 1.0;
|
x1 = 2.0 * CombLCGTaus() - 1.0;
|
||||||
x2 = 2.0 * CombLCGTaus() - 1.0;
|
x2 = 2.0 * CombLCGTaus() - 1.0;
|
||||||
|
|
@ -270,7 +266,6 @@ int poisson(double lambda)
|
||||||
{
|
{
|
||||||
int k=0; //Counter
|
int k=0; //Counter
|
||||||
const int max_k = 1000; //k upper limit
|
const int max_k = 1000; //k upper limit
|
||||||
checkseed();
|
|
||||||
double p = CombLCGTaus(); //uniform random number
|
double p = CombLCGTaus(); //uniform random number
|
||||||
double P = exp(-lambda); //probability
|
double P = exp(-lambda); //probability
|
||||||
double sum=P; //cumulant
|
double sum=P; //cumulant
|
||||||
|
|
@ -288,7 +283,6 @@ int poisson(double lambda)
|
||||||
double exprand(double mean)
|
double exprand(double mean)
|
||||||
{
|
{
|
||||||
double expval;
|
double expval;
|
||||||
checkseed();
|
|
||||||
expval = -log(CombLCGTaus()) * mean;
|
expval = -log(CombLCGTaus()) * mean;
|
||||||
return expval;
|
return expval;
|
||||||
}
|
}
|
||||||
|
|
@ -313,14 +307,20 @@ com_sseed(wordlist *wl)
|
||||||
srand((unsigned int)newseed);
|
srand((unsigned int)newseed);
|
||||||
TausSeed();
|
TausSeed();
|
||||||
}
|
}
|
||||||
else
|
else if ((sscanf(wl->wl_word, " %d ", &newseed) != 1) ||
|
||||||
if ((sscanf(wl->wl_word, " %d ", &newseed) != 1) || (newseed <= 0) || (newseed > INT_MAX)) {
|
(newseed <= 0) || (newseed > INT_MAX))
|
||||||
fprintf(cp_err, "Warning: Cannot use %s as seed!\n\n", wl->wl_word);
|
{
|
||||||
return;
|
fprintf(cp_err,
|
||||||
}
|
"\nWarning: Cannot use %s as seed!\n"
|
||||||
else {
|
" Command 'setseed %s' ignored.\n\n",
|
||||||
srand((unsigned int)newseed);
|
wl->wl_word, wl->wl_word);
|
||||||
TausSeed();
|
return;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
srand((unsigned int)newseed);
|
||||||
|
TausSeed();
|
||||||
|
cp_vset("rndseed", CP_NUM, &newseed);
|
||||||
|
}
|
||||||
|
|
||||||
printf("\nSeed value for random number generator is set to %d\n", newseed);
|
printf("\nSeed value for random number generator is set to %d\n", newseed);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -582,9 +582,10 @@ ngSpice_Init(SendChar* printfcn, SendStat* statusfcn, ControlledExit* ngspiceexi
|
||||||
/* program name*/
|
/* program name*/
|
||||||
cp_program = ft_sim->simulator;
|
cp_program = ft_sim->simulator;
|
||||||
|
|
||||||
int ii = getpid();
|
/* initialze random number generator with seed = 1 */
|
||||||
|
int ii = 1;
|
||||||
cp_vset("rndseed", CP_NUM, &ii);
|
cp_vset("rndseed", CP_NUM, &ii);
|
||||||
checkseed();
|
com_sseed(NULL);
|
||||||
|
|
||||||
/* set a boolean variable to be used in .control sections */
|
/* set a boolean variable to be used in .control sections */
|
||||||
bool sm = TRUE;
|
bool sm = TRUE;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
alias exit quit
|
alias exit quit
|
||||||
alias acct rusage all
|
alias acct rusage all
|
||||||
set x11lineararcs
|
set x11lineararcs
|
||||||
*set rndseed=12
|
*setseed 12
|
||||||
** ascii rawfile **
|
** ascii rawfile **
|
||||||
*set filetype=ascii
|
*set filetype=ascii
|
||||||
** frontend debug output **
|
** frontend debug output **
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue