Skip to content
Snippets Groups Projects
Commit 5a2a6074 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Add function to give a different seed for randoms

parent 67bd6d88
No related branches found
No related tags found
1 merge request!506Add ParMETIS support
......@@ -30,6 +30,7 @@
/* Standard headers. */
#include <stdio.h>
#include <limits.h>
#include <unistd.h>
/* Local headers. */
......@@ -280,3 +281,23 @@ double clocks_get_cputime_used(void) {
times(&tmstic);
return (double)(tmstic.tms_utime + tmstic.tms_cutime);
}
/**
* @brief Return an integer based on the current time.
*
* Normally this will be the remainder of the current number of nanoseconds
* so not very dissimilar in the most significant figures unless the time
* between calls is greater than INT_MAX nanoseconds. For faster calls use
* fewer figures, if that matters.
*
* @result an integer.
*/
int clocks_random_seed(void) {
struct timespec timespec;
#ifdef HAVE_CLOCK_GETTIME
clock_gettime(CLOCK_REALTIME, &timespec);
return (timespec.tv_nsec % INT_MAX);
#else
return (getticks() % INT_MAX);
#endif
}
......@@ -44,5 +44,6 @@ double clocks_diff_ticks(ticks tic, ticks toc);
const char *clocks_get_timesincestart(void);
double clocks_get_cputime_used(void);
int clocks_random_seed(void);
#endif /* SWIFT_CLOCKS_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment