xref: /freebsd-11-stable/contrib/llvm-project/compiler-rt/lib/gwp_asan/random.cpp (revision 8ce8be0a003b95ab7796df15e97ca5944b8536ac)
1 //===-- random.cpp ----------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "gwp_asan/random.h"
10 #include "gwp_asan/guarded_pool_allocator.h"
11 
12 #include <time.h>
13 
14 namespace gwp_asan {
getRandomUnsigned32()15 uint32_t getRandomUnsigned32() {
16   thread_local uint32_t RandomState =
17       time(nullptr) + GuardedPoolAllocator::getThreadID();
18   RandomState ^= RandomState << 13;
19   RandomState ^= RandomState >> 17;
20   RandomState ^= RandomState << 5;
21   return RandomState;
22 }
23 } // namespace gwp_asan
24