File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change 5
5
#include < cstdint>
6
6
#include < cstdlib>
7
7
#include < cmath>
8
+ #include < ctime>
8
9
#include < random>
9
10
#include < sstream>
10
11
#include < iomanip>
11
12
#include < algorithm>
13
+ #include < thread>
12
14
13
15
#include " ast.hpp"
14
16
#include " units.hpp"
@@ -41,8 +43,25 @@ namespace Sass {
41
43
#else
42
44
uint64_t GetSeed ()
43
45
{
44
- std::random_device rd;
45
- return rd ();
46
+ // Init universe entropy
47
+ uint64_t rnd = 42 ;
48
+ // Try to get random number from system
49
+ try {
50
+ std::random_device rd;
51
+ rnd = rd ();
52
+ }
53
+ // On certain system this can throw since either
54
+ // underlying hardware or software can be buggy.
55
+ // https://github.com/sass/libsass/issues/3151
56
+ catch (std::exception&) {
57
+ }
58
+ // Don't trust anyone to be random, so we
59
+ // add a little entropy of our own.
60
+ rnd ^= std::time (NULL ) ^ std::clock () ^
61
+ std::hash<std::thread::id>()
62
+ (std::this_thread::get_id ());
63
+ // Return entropy
64
+ return rnd;
46
65
}
47
66
#endif
48
67
You can’t perform that action at this time.
0 commit comments