fml  0.1-0
Fused Matrix Library
fmlutils.hh
1 // This file is part of fml which is released under the Boost Software
2 // License, Version 1.0. See accompanying file LICENSE or copy at
3 // https://www.boost.org/LICENSE_1_0.txt
4 
5 #ifndef FML__UTILS_FMLUTILS_H
6 #define FML__UTILS_FMLUTILS_H
7 #pragma once
8 
9 
10 #include <ctime>
11 
12 #include "platform.h"
13 
14 #if OS_WINDOWS
15 #include <process.h>
16 #elif OS_NIX
17 #include <sys/types.h>
18 #include <unistd.h>
19 #endif
20 
21 
22 namespace fmlutils
23 {
24  namespace
25  {
26  // Robert Jenkins' 96-bit mix function
27  inline uint32_t mix_96(uint32_t a, uint32_t b, uint32_t c)
28  {
29  a=a-b; a=a-c; a=a^(c >> 13);
30  b=b-c; b=b-a; b=b^(a << 8);
31  c=c-a; c=c-b; c=c^(b >> 13);
32  a=a-b; a=a-c; a=a^(c >> 12);
33  b=b-c; b=b-a; b=b^(a << 16);
34  c=c-a; c=c-b; c=c^(b >> 5);
35  a=a-b; a=a-c; a=a^(c >> 3);
36  b=b-c; b=b-a; b=b^(a << 10);
37  c=c-a; c=c-b; c=c^(b >> 15);
38 
39  return c;
40  }
41  }
42 
43 
44 
45  inline uint32_t get_seed()
46  {
47  uint32_t pid;
48  uint32_t ret;
49 
50  #if OS_WINDOWS
51  pid = _getpid();
52  #elif OS_NIX
53  pid = (uint32_t) getpid();
54  #else
55  #error "Unable to get PID"
56  #endif
57 
58  ret = mix_96((uint32_t) time(NULL), (uint32_t) clock(), pid);
59 
60  return ret;
61  }
62 }
63 
64 
65 #endif
Definition: fmlutils.hh:22