Represents a pseudo-random number generator, a device that produces a sequence of numbers that meet certain statistical requirements for randomness.
Protected Member Functions | |
virtual double | sample () const |
Returns a random number between 0.0 and 1.0. | |
Public Constructors | |
random () | |
Initializes a new instance of the random class, using a default generated seed value. | |
random (uint32 seed) | |
Initializes a new instance of the random class, using a specified seed value. | |
random (std::random_device &random_device) | |
Initializes a new instance of the random class, using a specified random device value. | |
Public Properties | |
const std::default_random_engine & | generator () const noexcept |
Gets the underlying generator. | |
std::default_random_engine & | generator () noexcept |
Gets the underlying generator. | |
Public Methods | |
template<class value_t > | |
xtd::array< value_t > | get_items (const xtd::read_only_span< value_t > &choices, xtd::size length) |
Creates an array populated with items chosen at random from the provided set of choices. | |
template<class value_t > | |
xtd::array< value_t > | get_items (const xtd::array< value_t > &choices, xtd::size length) |
Creates an array populated with items chosen at random from the provided set of choices. | |
template<class value_t > | |
void | get_items (const xtd::read_only_span< value_t > &choices, xtd::span< value_t > &destination) |
Fills the elements of a specified span with items chosen at random from the provided set of choices. | |
virtual int32 | next () const |
Returns a nonnegative random number. | |
template<class value_t > | |
value_t | next () const |
Returns a nonnegative random number. | |
virtual int32 | next (int32 max_value) const |
Returns a nonnegative random number less than the specified maximum. | |
template<class value_t > | |
value_t | next (value_t max_value) const |
Returns a nonnegative random number less than the specified maximum. | |
virtual int32 | next (int32 min_value, int32 max_value) const |
Returns a random number within a specified range. | |
template<class value_t > | |
value_t | next (value_t min_value, value_t max_value) const |
Returns a random number within a specified range. | |
virtual void | next_bytes (xtd::span< xtd::byte > &buffer) const |
Fills the elements of a specified array of bytes with random numbers. | |
virtual void | next_bytes (xtd::array< xtd::byte > &buffer) const |
Fills the elements of a specified array of bytes with random numbers. | |
virtual double | next_double () const |
Returns a random number between 0.0 and 1.0. | |
template<class value_t > | |
void | next_values (xtd::span< value_t > &buffer) const |
Fills the elements of a specified xtd::span of bytes with random numbers. | |
template<class value_t > | |
void | next_values (xtd::array< value_t > &buffer) const |
Fills the elements of a specified array of bytes with random numbers. | |
virtual int64 | next_int64 () const |
Returns a nonnegative random number. | |
virtual int64 | next_int64 (int64 max_value) const |
Returns a nonnegative random number less than the specified maximum. | |
virtual int64 | next_int64 (int64 min_value, int64 max_value) const |
Returns a random number within a specified range. | |
virtual single | next_single () const |
Returns a random number between 0.0 and 1.0. | |
template<class value_t > | |
void | shuffle (xtd::span< value_t > &values) const |
Performs an in-place shuffle of a span. | |
template<class collection_t > | |
void | shuffle (collection_t &values) const |
Performs an in-place shuffle of an array. | |
Additional Inherited Members | |
![]() | |
object ()=default | |
Create a new instance of the ultimate base class object. | |
virtual bool | equals (const object &obj) const noexcept |
Determines whether the specified object is equal to the current object. | |
virtual xtd::size | get_hash_code () const noexcept |
Serves as a hash function for a particular type. | |
virtual type_object | get_type () const noexcept |
Gets the type of the current instance. | |
template<class object_t > | |
xtd::uptr< object_t > | memberwise_clone () const |
Creates a shallow copy of the current object. | |
virtual xtd::string | to_string () const noexcept |
Returns a xtd::string that represents the current object. | |
![]() | |
template<class object_a_t , class object_b_t > | |
static bool | equals (const object_a_t &object_a, const object_b_t &object_b) noexcept |
Determines whether the specified object instances are considered equal. | |
template<class object_a_t , class object_b_t > | |
static bool | reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept |
Determines whether the specified object instances are the same instance. | |
xtd::random::random | ( | ) |
Initializes a new instance of the random class, using a default generated seed value.
|
explicit |
Initializes a new instance of the random class, using a specified seed value.
seed | A number used to calculate a starting value for the pseudo-random number sequence. |
|
explicit |
Initializes a new instance of the random class, using a specified random device value.
random_device | A random device value. |
|
noexcept |
Gets the underlying generator.
|
noexcept |
Gets the underlying generator.
|
inline |
Creates an array populated with items chosen at random from the provided set of choices.
choices | Set of choices. |
length | The length of the populated array. |
|
inline |
Creates an array populated with items chosen at random from the provided set of choices.
choices | Set of choices. |
length | The length of the populated array. |
|
inline |
Fills the elements of a specified span with items chosen at random from the provided set of choices.
choices | Set of choices. |
destination | The elements to fill. |
|
virtual |
Returns a nonnegative random number.
|
inline |
Returns a nonnegative random number.
Returns a nonnegative random number less than the specified maximum.
max_value | The exclusive upper bound of the random number to be generated. max_value must be greater than or equal to zero. |
argument_out_of_range_exception | max_value is less than zero. |
|
inline |
Returns a nonnegative random number less than the specified maximum.
max_value | The exclusive upper bound of the random number to be generated. max_value must be greater than or equal to zero. |
argument_out_of_range_exception | max_value is less than zero. |
Returns a random number within a specified range.
min_value | The inclusive lower bound of the random number returned |
max_value | The exclusive upper bound of the random number returned. max_value must be greater than or equal to min_value. |
argument_out_of_range_exception | min_value is greater than max_value. |
|
inline |
Returns a random number within a specified range.
min_value | The inclusive lower bound of the random number returned |
max_value | The exclusive upper bound of the random number returned. max_value must be greater than or equal to min_value. |
argument_out_of_range_exception | min_value is greater than max_value. |
Fills the elements of a specified array of bytes with random numbers.
buffer | An array of bytes to contain random numbers. |
|
virtual |
Fills the elements of a specified array of bytes with random numbers.
buffer | An array of bytes to contain random numbers. |
|
virtual |
Returns a random number between 0.0 and 1.0.
|
inline |
Fills the elements of a specified xtd::span of bytes with random numbers.
buffer | An xtd::span of bytes to contain random numbers. |
|
inline |
Fills the elements of a specified array of bytes with random numbers.
buffer | An array of bytes to contain random numbers. |
|
virtual |
Returns a nonnegative random number.
Returns a nonnegative random number less than the specified maximum.
max_value | The exclusive upper bound of the random number to be generated. max_value must be greater than or equal to zero. |
argument_out_of_range_exception | max_value is less than zero. |
Returns a random number within a specified range.
min_value | The inclusive lower bound of the random number returned |
max_value | The exclusive upper bound of the random number returned. max_value must be greater than or equal to min_value. |
argument_out_of_range_exception | min_value is greater than max_value. |
|
virtual |
Returns a random number between 0.0 and 1.0.
|
inline |
Performs an in-place shuffle of a span.
values | The span to shuffle. |
|
inline |
Performs an in-place shuffle of an array.
values | The array to shuffle. |
|
protectedvirtual |
Returns a random number between 0.0 and 1.0.