44 explicit random(uint32_t seed) : generator_(seed + 1) {}
48 explicit random(std::random_device& random_device) : generator_(random_device()) {}
52 virtual int32_t
next()
const {
return next(std::numeric_limits<int32_t>::max());}
56 template<
typename value_t>
57 value_t
next()
const {
return next(std::numeric_limits<value_t>::max());}
64 virtual int32_t
next(int32_t max_value)
const {
return next(0, max_value);}
71 template<
typename value_t>
72 value_t
next(value_t max_value)
const {
return next(0, max_value);}
81 virtual int32_t
next(int32_t min_value, int32_t max_value)
const {
83 if (min_value == max_value)
return min_value;
84 return min_value +
static_cast<int32_t
>(std::round(
sample() * std::numeric_limits<int32_t>::max())) % ((max_value - 1) - min_value + 1);
94 template<
typename value_t>
95 value_t
next(value_t min_value, value_t max_value)
const {
97 if (min_value == max_value)
return min_value;
98 return min_value +
static_cast<value_t
>(std::round(
sample() * std::numeric_limits<value_t>::max())) % ((max_value - 1) - min_value + 1);
110 virtual void next_bytes(uint8_t* buffer,
size_t buffer_size)
const {
112 for (
size_t index = 0; index < buffer_size; index++)
113 buffer[index] = next<uint8_t>(0, std::numeric_limits<uint8_t>::max());
119 template<
typename value_t>
126 template<
typename value_t>
129 for (
size_t index = 0; index < buffer_size; index++)
130 buffer[index] = next<value_t>(0, std::numeric_limits<value_t>::max());
143 static std::uniform_real_distribution<> distribution_(0, 1);
144 return distribution_(generator_);
148 mutable std::default_random_engine generator_;
Contains xtd::argument_null_exception exception.
Contains xtd::argument_out_of_range_exception exception.
The exception that is thrown when one of the arguments provided to a method is null.
Definition argument_null_exception.h:18
The exception that is thrown when one of the arguments provided to a method is out of range.
Definition argument_out_of_range_exception.h:18
The environment class.
Definition environment.h:33
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:26
Represents a pseudo-random number generator, a device that produces a sequence of numbers that meet c...
Definition random.h:37
value_t next(value_t max_value) const
Returns a nonnegative random number less than the specified maximum.
Definition random.h:72
virtual void next_bytes(std::vector< uint8_t > &buffer) const
Fills the elements of a specified array of bytes with random numbers.
Definition random.h:104
virtual void next_bytes(uint8_t *buffer, size_t buffer_size) const
Fills the elements of a specified array of bytes with random numbers.
Definition random.h:110
random(uint32_t seed)
Initializes a new instance of the random class, using a specified seed value.
Definition random.h:44
virtual double next_double() const
Returns a random number between 0.0 and 1.0.
Definition random.h:136
void next_values(value_t *buffer, size_t buffer_size) const
Fills the elements of a specified array of bytes with random numbers.
Definition random.h:127
virtual int32_t next(int32_t min_value, int32_t max_value) const
Returns a random number within a specified range.
Definition random.h:81
random(std::random_device &random_device)
Initializes a new instance of the random class, using a specified random device value.
Definition random.h:48
virtual int32_t next(int32_t max_value) const
Returns a nonnegative random number less than the specified maximum.
Definition random.h:64
value_t next(value_t min_value, value_t max_value) const
Returns a random number within a specified range.
Definition random.h:95
value_t next() const
Returns a nonnegative random number.
Definition random.h:57
void next_values(std::vector< value_t > &buffer) const
Fills the elements of a specified array of bytes with random numbers.
Definition random.h:120
random()
Initializes a new instance of the random class, using a default generated seed value.
Definition random.h:40
virtual int32_t next() const
Returns a nonnegative random number.
Definition random.h:52
virtual double sample() const
Returns a random number between 0.0 and 1.0.
Definition random.h:142
Contains core_export_ keyword.
Contains xtd::environment class.
#define current_stack_frame_
Provides information about the current stack frame.
Definition stack_frame.h:201
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition system_report.h:17
Contains xtd::object class.