diff --git a/src/frontend/inp.c b/src/frontend/inp.c index 228c63526..b226325de 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -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; diff --git a/src/misc/win_time.c b/src/misc/win_time.c new file mode 100644 index 000000000..fd1788d7e --- /dev/null +++ b/src/misc/win_time.c @@ -0,0 +1,32 @@ +#define WIN32_LEAN_AND_MEAN +//#include "ngspice/ngspice.h" +#include +#include +#include // 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; +} diff --git a/visualc/sharedspice.vcxproj b/visualc/sharedspice.vcxproj index 6ddb78d3c..e0dac4480 100644 --- a/visualc/sharedspice.vcxproj +++ b/visualc/sharedspice.vcxproj @@ -1220,6 +1220,7 @@ + diff --git a/visualc/vngspice-fftw.vcxproj b/visualc/vngspice-fftw.vcxproj index 27e22eff9..a5dd55c63 100644 --- a/visualc/vngspice-fftw.vcxproj +++ b/visualc/vngspice-fftw.vcxproj @@ -1685,6 +1685,7 @@ lib /machine:x64 /def:..\..\fftw-3.3-dll64\libfftw3-3.def /out:$(IntDir)libfftw3 + diff --git a/visualc/vngspice.vcxproj b/visualc/vngspice.vcxproj index f366c96c3..279cc36d8 100644 --- a/visualc/vngspice.vcxproj +++ b/visualc/vngspice.vcxproj @@ -1700,6 +1700,7 @@ +