NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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&
38
getSecureRandomGenerator
()
39
{
40
static
CryptoPP::AutoSeededRandomPool rng;
41
42
return
rng;
43
}
44
45
uint32_t
46
generateSecureWord32
()
47
{
48
return
getSecureRandomGenerator
().GenerateWord32();
49
}
50
51
uint64_t
52
generateSecureWord64
()
53
{
54
uint64_t random;
55
getSecureRandomGenerator
()
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&
64
getRandomGenerator
()
65
{
66
static
boost::random_device randomSeedGenerator;
67
static
boost::random::mt19937 gen(randomSeedGenerator);
68
69
return
gen;
70
}
71
72
uint32_t
73
generateWord32
()
74
{
75
static
boost::random::uniform_int_distribution<uint32_t> distribution;
76
return
distribution(
getRandomGenerator
());
77
}
78
79
uint64_t
80
generateWord64
()
81
{
82
static
boost::random::uniform_int_distribution<uint64_t> distribution;
83
return
distribution(
getRandomGenerator
());
84
}
85
86
87
}
// namespace random
88
}
// namespace ndn
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::random::generateSecureWord64
uint64_t generateSecureWord64()
Generate a cryptographically secure random integer from the range [0, 2^64)
Definition:
random.cpp:52
ndn::random::generateWord32
uint32_t generateWord32()
Generate a cryptographically non-secure random integer from the range [0, 2^32)
Definition:
random.cpp:73
ndn::random::generateSecureWord32
uint32_t generateSecureWord32()
Generate a cryptographically secure random integer from the range [0, 2^32)
Definition:
random.cpp:46
ndn::random::getSecureRandomGenerator
static CryptoPP::AutoSeededRandomPool & getSecureRandomGenerator()
Definition:
random.cpp:38
random.hpp
ndn::random::getRandomGenerator
static boost::random::mt19937 & getRandomGenerator()
Definition:
random.cpp:64
ndn::random::generateWord64
uint64_t generateWord64()
Generate a cryptographically non-secure random integer from range [0, 2^64)
Definition:
random.cpp:80
ndnSIM
ndn-cxx
src
util
random.cpp
Generated on Tue Feb 23 2016 22:18:44 for ndnSIM by
1.8.11