DotNetDupe
4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Toggle main menu visibility
Loading...
Searching...
No Matches
Random.cpp
Go to the documentation of this file.
1
#include "
pch.h
"
2
#include "
System/Random.h
"
3
#include <random>
4
5
namespace
DotNetDupe
{
6
namespace
System
{
7
Random::Random
() : _seed(0) { }
8
9
Random::Random
(
int
seed) : _seed(seed) { }
10
11
int
Random::Next
() {
13
std::mt19937 gen(_seed);
14
std::uniform_int_distribution<> distrib(0, 2147483647);
15
return
distrib(gen);
16
}
17
18
int
Random::Next
(
int
maxValue) {
20
std::mt19937 gen(_seed);
21
std::uniform_int_distribution<> distrib(0, maxValue);
22
return
distrib(gen);
23
}
24
25
int
Random::Next
(
int
minValue,
int
maxValue) {
27
std::mt19937 gen(_seed);
28
std::uniform_int_distribution<> distrib(minValue, maxValue);
29
return
distrib(gen);
30
}
31
32
void
Random::NextBytes
(
unsigned
char
* buffer,
int
bufferSize) {
34
std::mt19937 gen(_seed);
35
std::uniform_int_distribution<> distrib(0, 255);
36
for
(
int
i = 0; i < bufferSize; ++i) {
37
buffer [i] =
static_cast<
unsigned
char
>
(distrib(gen));
38
}
39
}
40
41
double
Random::NextDouble
() {
43
std::mt19937 gen(_seed);
44
std::uniform_real_distribution<> distrib(0.0, 1.0);
45
return
distrib(gen);
46
}
47
}
48
}
Random.h
Represents a pseudo-random number generator.
DotNetDupe::System::Random::NextDouble
virtual double NextDouble()
Returns a random floating-point number that is greater than or equal to 0.0, and less than 1....
Definition
Random.cpp:41
DotNetDupe::System::Random::Random
Random()
Initializes a new instance of the Random class, using a time-dependent default seed value.
Definition
Random.cpp:7
DotNetDupe::System::Random::Next
virtual int Next()
Returns a non-negative random integer.
Definition
Random.cpp:11
DotNetDupe::System::Random::NextBytes
virtual void NextBytes(unsigned char *buffer, int bufferSize)
Fills the elements of a specified array of bytes with random numbers.
Definition
Random.cpp:32
DotNetDupe::System
Definition
Action.h:11
DotNetDupe
Definition
IServiceCollection.h:7
pch.h
DotNetDupe
Random.cpp
Generated by
1.18.0