Generate seed numbers from a microseconds clock, not a seconds clock
This commit is contained in:
parent
81bb886c71
commit
70e366021b
|
|
@ -89,6 +89,16 @@ extern void exec_controls(wordlist *controls);
|
|||
extern void SetSource(char *Name);
|
||||
#endif
|
||||
|
||||
#if defined (_MSC_VER) || defined (__MINGW32__)
|
||||
typedef struct timeval {
|
||||
long tv_sec;
|
||||
long tv_usec;
|
||||
} timeval;
|
||||
|
||||
extern int gettimeofday(struct timeval* tp, void* unused);
|
||||
#endif
|
||||
|
||||
|
||||
/* structure used to save expression parse trees for .model and
|
||||
* device instance lines
|
||||
*/
|
||||
|
|
@ -101,6 +111,7 @@ struct pt_temper {
|
|||
struct pt_temper *next;
|
||||
};
|
||||
|
||||
|
||||
static int inp_parse_temper(struct card *deck,
|
||||
struct pt_temper **motdlist_p,
|
||||
struct pt_temper **devtlist_p);
|
||||
|
|
@ -439,9 +450,10 @@ eval_opt(struct card* deck)
|
|||
char* token = gettok(&begtok);
|
||||
/* option seed=random [seed='random'] */
|
||||
if (eq(token, "random") || eq(token, "{random}")) {
|
||||
time_t acttime = time(NULL);
|
||||
/* get random value from time in seconds since 1.1.1970 */
|
||||
int rseed = (int)(acttime - 1600000000);
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
/* get random value from current timestamp microseconds */
|
||||
int rseed = (int)(tv.tv_usec);
|
||||
cp_vset("rndseed", CP_NUM, &rseed);
|
||||
com_sseed(NULL);
|
||||
has_seed = TRUE;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
#define WIN32_LEAN_AND_MEAN
|
||||
//#include "ngspice/ngspice.h"
|
||||
#include <Windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <stdint.h> // portable: uint64_t MSVC: __int64
|
||||
|
||||
/*/ MSVC defines this in winsock2.h!?
|
||||
typedef struct timeval {
|
||||
long tv_sec;
|
||||
long tv_usec;
|
||||
} timeval;
|
||||
*/
|
||||
int gettimeofday(struct timeval * tp, void * unused)
|
||||
{
|
||||
// Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's
|
||||
// This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
|
||||
// until 00:00:00 January 1, 1970
|
||||
static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL);
|
||||
|
||||
SYSTEMTIME system_time;
|
||||
FILETIME file_time;
|
||||
uint64_t time;
|
||||
|
||||
GetSystemTime( &system_time );
|
||||
SystemTimeToFileTime( &system_time, &file_time );
|
||||
time = ((uint64_t)file_time.dwLowDateTime ) ;
|
||||
time += ((uint64_t)file_time.dwHighDateTime) << 32;
|
||||
|
||||
tp->tv_sec = (long) ((time - EPOCH) / 10000000L);
|
||||
tp->tv_usec = (long) (system_time.wMilliseconds * 1000);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1220,6 +1220,7 @@
|
|||
<ClCompile Include="..\src\misc\string.c" />
|
||||
<ClCompile Include="..\src\misc\tilde.c" />
|
||||
<ClCompile Include="..\src\misc\util.c" />
|
||||
<ClCompile Include="..\src\misc\win_time.c" />
|
||||
<ClCompile Include="..\src\misc\wlist.c" />
|
||||
<ClCompile Include="..\src\ngspice.c" />
|
||||
<ClCompile Include="..\src\osdi\osdiacld.c" />
|
||||
|
|
|
|||
|
|
@ -1685,6 +1685,7 @@ lib /machine:x64 /def:..\..\fftw-3.3-dll64\libfftw3-3.def /out:$(IntDir)libfftw3
|
|||
<ClCompile Include="..\src\misc\string.c" />
|
||||
<ClCompile Include="..\src\misc\tilde.c" />
|
||||
<ClCompile Include="..\src\misc\util.c" />
|
||||
<ClCompile Include="..\src\misc\win_time.c" />
|
||||
<ClCompile Include="..\src\misc\wlist.c" />
|
||||
<ClCompile Include="..\src\ngspice.c" />
|
||||
<ClCompile Include="..\src\osdi\osdiacld.c" />
|
||||
|
|
|
|||
|
|
@ -1700,6 +1700,7 @@
|
|||
<ClCompile Include="..\src\misc\string.c" />
|
||||
<ClCompile Include="..\src\misc\tilde.c" />
|
||||
<ClCompile Include="..\src\misc\util.c" />
|
||||
<ClCompile Include="..\src\misc\win_time.c" />
|
||||
<ClCompile Include="..\src\misc\wlist.c" />
|
||||
<ClCompile Include="..\src\ngspice.c" />
|
||||
<ClCompile Include="..\src\osdi\osdiacld.c" />
|
||||
|
|
|
|||
Loading…
Reference in New Issue