NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
random.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "common.hpp"
23 
24 #include "random.hpp"
25 
26 #include <boost/nondet_random.hpp>
27 #include <boost/random/mersenne_twister.hpp>
28 #include <boost/random/uniform_int_distribution.hpp>
29 
30 #include "../security/cryptopp.hpp"
31 
32 namespace ndn {
33 namespace random {
34 
35 // CryptoPP-based (secure) random generators
36 
37 static CryptoPP::AutoSeededRandomPool&
39 {
40  static CryptoPP::AutoSeededRandomPool rng;
41 
42  return rng;
43 }
44 
45 uint32_t
47 {
48  return getSecureRandomGenerator().GenerateWord32();
49 }
50 
51 uint64_t
53 {
54  uint64_t random;
56  .GenerateBlock(reinterpret_cast<unsigned char*>(&random), sizeof(uint64_t));
57 
58  return random;
59 }
60 
61 // Boost.Random-based (simple) random generators
62 
63 static boost::random::mt19937&
65 {
66  static boost::random_device randomSeedGenerator;
67  static boost::random::mt19937 gen(randomSeedGenerator);
68 
69  return gen;
70 }
71 
72 uint32_t
74 {
75  static boost::random::uniform_int_distribution<uint32_t> distribution;
76  return distribution(getRandomGenerator());
77 }
78 
79 uint64_t
81 {
82  static boost::random::uniform_int_distribution<uint64_t> distribution;
83  return distribution(getRandomGenerator());
84 }
85 
86 
87 } // namespace random
88 } // namespace ndn
Copyright (c) 2011-2015 Regents of the University of California.
uint64_t generateSecureWord64()
Generate a cryptographically secure random integer from the range [0, 2^64)
Definition: random.cpp:52
uint32_t generateWord32()
Generate a cryptographically non-secure random integer from the range [0, 2^32)
Definition: random.cpp:73
uint32_t generateSecureWord32()
Generate a cryptographically secure random integer from the range [0, 2^32)
Definition: random.cpp:46
static CryptoPP::AutoSeededRandomPool & getSecureRandomGenerator()
Definition: random.cpp:38
static boost::random::mt19937 & getRandomGenerator()
Definition: random.cpp:64
uint64_t generateWord64()
Generate a cryptographically non-secure random integer from range [0, 2^64)
Definition: random.cpp:80