Class thrust::random::uniform_real_distribution
A uniform_real_distribution
random number distribution produces floating point uniform random numbers from a half-open interval.
The following code snippet demonstrates examples of using a uniform_real_distribution
with a random number engine to produce random integers drawn from a given range:
#include <thrust/random/linear_congruential_engine.h>
#include <thrust/random/uniform_real_distribution.h>
int main()
{
// create a minstd_rand object to act as our source of randomness
thrust::minstd_rand rng;
// create a uniform_real_distribution to produce floats from [-7,13)
thrust::uniform_real_distribution<float> dist(-7,13);
// write a random number from the range [-7,13) to standard output
std::cout << dist(rng) << std::endl;
// write the range of the distribution, just in case we forgot
std::cout << dist.min() << std::endl;
// -7.0 is printed
std::cout << dist.max() << std::endl;
// 13.0 is printed
// write the parameters of the distribution (which happen to be the bounds) to standard output
std::cout << dist.a() << std::endl;
// -7.0 is printed
std::cout << dist.b() << std::endl;
// 13.0 is printed
return 0;
}
Template Parameters: RealType
: The type of floating point number to produce.
#include <thrust/random/uniform_real_distribution.h>
template <typename RealType = double> class thrust::random::uniform_real_distribution { public:
/* The type of the floating point number produced by this uniform_real_distribution
. */ typedef see below result_type;
/* The type of the object encapsulating this uniform_real_distribution's
parameters. */ typedef see below param_type;
explicit _CCCL_HOST_DEVICE uniform_real_distribution(RealType a = 0.0, RealType b = 1.0);
explicit _CCCL_HOST_DEVICE uniform_real_distribution(const param_type & parm);
_CCCL_HOST_DEVICE void reset();
template <typename UniformRandomNumberGenerator> _CCCL_HOST_DEVICE result_type operator()(UniformRandomNumberGenerator & urng);
template <typename UniformRandomNumberGenerator> _CCCL_HOST_DEVICE result_type operator()(UniformRandomNumberGenerator & urng, const param_type & parm);
_CCCL_HOST_DEVICE result_type a() const;
_CCCL_HOST_DEVICE result_type b() const;
_CCCL_HOST_DEVICE param_type param() const;
_CCCL_HOST_DEVICE void param(const param_type & parm);
_CCCL_HOST_DEVICE result_type min THRUST_PREVENT_MACRO_SUBSTITUTION() const;
_CCCL_HOST_DEVICE result_type max THRUST_PREVENT_MACRO_SUBSTITUTION() const; };
Member Types
Typedef thrust::random::uniform_real_distribution::result_type
typedef RealTyperesult_type;
The type of the floating point number produced by this uniform_real_distribution
.
Typedef thrust::random::uniform_real_distribution::param_type
typedef thrust::pair< RealType, RealType >param_type;
The type of the object encapsulating this uniform_real_distribution's
parameters.
Member Functions
Function thrust::random::uniform_real_distribution::uniform_real_distribution
explicit _CCCL_HOST_DEVICE uniform_real_distribution(RealType a = 0.0, RealType b = 1.0);
This constructor creates a new uniform_real_distribution
from two values defining the half-open interval of the distribution.
Function Parameters:
a
The smallest floating point number to potentially produce. Defaults to0.0
.b
The smallest number larger than the largest floating point number to potentially produce. Defaults to1.0
.
Function thrust::random::uniform_real_distribution::uniform_real_distribution
explicit _CCCL_HOST_DEVICE uniform_real_distribution(const param_type & parm);
This constructor creates a new uniform_real_distribution
from a param_type
object encapsulating the range of the distribution.
Function Parameters: parm
: A param_type
object encapsulating the parameters (i.e., the range) of the distribution.
Function thrust::random::uniform_real_distribution::reset
_CCCL_HOST_DEVICE void reset();
This does nothing. It is included to conform to the requirements of the RandomDistribution concept.
Function thrust::random::uniform_real_distribution::operator()
template <typename UniformRandomNumberGenerator> _CCCL_HOST_DEVICE result_type operator()(UniformRandomNumberGenerator & urng);
This method produces a new uniform random integer drawn from this uniform_real_distribution's
range using a UniformRandomNumberGenerator
as a source of randomness.
Function Parameters: urng
: The UniformRandomNumberGenerator
to use as a source of randomness.
Function thrust::random::uniform_real_distribution::operator()
template <typename UniformRandomNumberGenerator> _CCCL_HOST_DEVICE result_type operator()(UniformRandomNumberGenerator & urng, const param_type & parm);
This method produces a new uniform random integer as if by creating a new uniform_real_distribution
from the given param_type
object, and calling its operator()
method with the given UniformRandomNumberGenerator
as a source of randomness.
Function Parameters:
urng
TheUniformRandomNumberGenerator
to use as a source of randomness.parm
Aparam_type
object encapsulating the parameters of theuniform_real_distribution
to draw from.
Function thrust::random::uniform_real_distribution::a
_CCCL_HOST_DEVICE result_type a() const;
This method returns the value of the parameter with which this uniform_real_distribution
was constructed.
Returns: The lower bound of this uniform_real_distribution's
half-open interval.
Function thrust::random::uniform_real_distribution::b
_CCCL_HOST_DEVICE result_type b() const;
This method returns the value of the parameter with which this uniform_real_distribution
was constructed.
Returns: The upper bound of this uniform_real_distribution's
half-open interval.
Function thrust::random::uniform_real_distribution::param
_CCCL_HOST_DEVICE param_type param() const;
This method returns a param_type
object encapsulating the parameters with which this uniform_real_distribution
was constructed.
Returns: A param_type
object enapsulating the half-open interval of this uniform_real_distribution
.
Function thrust::random::uniform_real_distribution::param
_CCCL_HOST_DEVICE void param(const param_type & parm);
This method changes the parameters of this uniform_real_distribution
using the values encapsulated in a given param_type
object.
Function Parameters: parm
: A param_type
object encapsulating the new half-open interval of this uniform_real_distribution
.
Function thrust::random::uniform_real_distribution::THRUST_PREVENT_MACRO_SUBSTITUTION
_CCCL_HOST_DEVICE result_type min THRUST_PREVENT_MACRO_SUBSTITUTION() const;
This method returns the smallest floating point number this uniform_real_distribution
can potentially produce.
Returns: The lower bound of this uniform_real_distribution's
half-open interval.
Function thrust::random::uniform_real_distribution::THRUST_PREVENT_MACRO_SUBSTITUTION
_CCCL_HOST_DEVICE result_type max THRUST_PREVENT_MACRO_SUBSTITUTION() const;
This method returns the smallest number larger than largest floating point number this uniform_real_distribution
can potentially produce.
Returns: The upper bound of this uniform_real_distribution's
half-open interval.