nikhilgupta10 / GridLAB-D

Other
1 stars 0 forks source link

#679 random seed in globals and randomvar lack entropy, #2419

Open nikhilgupta10 opened 8 years ago

nikhilgupta10 commented 8 years ago

If gridlabd is run twice in the same second, the random numbers come up the same even when they should be different. Recommend added additional sources of entropy in the srand() calls. Consider the pid, macaddr, and/or usec as additional sources of entropy.

,

nikhilgupta10 commented 8 years ago

nikhilgupta10 imported these comments from Sourceforge: The user dchassin does not exist anymore. Therefore assigning this to afisher1. "dchassin": * status changed from new to accepted

Started with changeset:3750

,

"dchassin": * status changed from accepted to closed

As of changeset:3751 there is an entropy source that includes the pid and time.

The current solution is much better, but not ideal: the behavior of this new entropy_source() call is not well-defined if called more than once per run (which is possible). If the entropy source is called twice in the same run in less than a second, it will return the same number. But if it's called twice in the same run more than a second apart it will return a different number.

,

"andyfisher":It appears as if this one has been fixed but not merged into trunk. Can you confirm this?,

"dchassin":I doesn't look like this has been fixed. I suggest using the microseconds also, this still leaves a potential lack of entropy if the call occurs twice within 1 microsecond, but that is very much less likely to occur than twice in 1 second.,

"andyfisher":- Description has changed:

Diff:

unsigned entropy_source(void)
{
        struct timeval t;
        gettimeofday(&t,NULL);
        return (unsigned)(getpid()*t.tv_usec);
}
~~~,

 "dchassin":By the way, this has *not* been addressed in trunk.  The problem persists but the fix is trivial.,