Fix = delete in MSVC build from r211705
[oota-llvm.git] / include / llvm / Support / RandomNumberGenerator.h
1 //==- llvm/Support/RandomNumberGenerator.h - RNG for diversity ---*- C++ -*-==//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines an abstraction for random number generation (RNG).
11 // Note that the current implementation is not cryptographically secure
12 // as it uses the C++11 <random> facilities.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_SUPPORT_RANDOMNUMBERGENERATOR_H_
17 #define LLVM_SUPPORT_RANDOMNUMBERGENERATOR_H_
18
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Support/DataTypes.h" // Needed for uint64_t on Windows.
21 #include <random>
22
23 namespace llvm {
24
25 /// A random number generator.
26 /// Instances of this class should not be shared across threads.
27 class RandomNumberGenerator {
28 public:
29   /// Seeds and salts the underlying RNG engine. The salt of type StringRef
30   /// is passed into the constructor. The seed can be set on the command
31   /// line via -rng-seed=<uint64>.
32   /// The reason for the salt is to ensure different random streams even if
33   /// the same seed is used for multiple invocations of the compiler.
34   /// A good salt value should add additional entropy and be constant across
35   /// different machines (i.e., no paths) to allow for reproducible builds.
36   /// An instance of this class can be retrieved from the current Module.
37   /// \see Module::getRNG
38   RandomNumberGenerator(StringRef Salt);
39
40   /// Returns a random number in the range [0, Max).
41   uint64_t next(uint64_t Max);
42
43 private:
44   // 64-bit Mersenne Twister by Matsumoto and Nishimura, 2000
45   // http://en.cppreference.com/w/cpp/numeric/random/mersenne_twister_engine
46   std::mt19937_64 Generator;
47
48   // Noncopyable.
49   RandomNumberGenerator(const RandomNumberGenerator &other)
50       LLVM_DELETED_FUNCTION;
51   RandomNumberGenerator &
52   operator=(const RandomNumberGenerator &other) LLVM_DELETED_FUNCTION;
53 };
54 }
55
56 #endif