Class thrust::random::normal_distribution

A normal_distribution random number distribution produces floating point Normally distributed random numbers.

The following code snippet demonstrates examples of using a normal_distribution with a random number engine to produce random values drawn from the Normal distribution with a given mean and variance:

#include <thrust/random/linear_congruential_engine.h>
#include <thrust/random/normal_distribution.h>

int main()
{
  // create a minstd_rand object to act as our source of randomness
  thrust::minstd_rand rng;

  // create a normal_distribution to produce floats from the Normal distribution
  // with mean 2.0 and standard deviation 3.5
  thrust::random::normal_distribution<float> dist(2.0f, 3.5f);

  // write a random number to standard output
  std::cout << dist(rng) << std::endl;

  // write the mean of the distribution, just in case we forgot
  std::cout << dist.mean() << std::endl;

  // 2.0 is printed

  // and the standard deviation
  std::cout << dist.stddev() << std::endl;

  // 3.5 is printed

  return 0;
}

Template Parameters: RealType: The type of floating point number to produce.

Inherits From: detail::normal_distribution_base::type

#include <thrust/random/normal_distribution.h>
template <typename RealType = double> class thrust::random::normal_distribution { public:   /* The type of the floating point number produced by this normal_distribution. */  typedef see below result_type;
   /* The type of the object encapsulating this normal_distribution's parameters. */  typedef see below param_type;
  explicit _CCCL_HOST_DEVICE   normal_distribution(RealType mean = 0.0,     RealType stddev = 1.0);
  explicit _CCCL_HOST_DEVICE   normal_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   mean() const;
  _CCCL_HOST_DEVICE result_type   stddev() 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::normal_distribution::result_type

typedef RealTyperesult_type; The type of the floating point number produced by this normal_distribution.

Typedef thrust::random::normal_distribution::param_type

typedef thrust::pair< RealType, RealType >param_type; The type of the object encapsulating this normal_distribution's parameters.

Member Functions

Function thrust::random::normal_distribution::normal_distribution

explicit _CCCL_HOST_DEVICE normal_distribution(RealType mean = 0.0,   RealType stddev = 1.0); This constructor creates a new normal_distribution from two values defining the half-open interval of the distribution.

Function Parameters:

  • mean The mean (expected value) of the distribution. Defaults to 0.0.
  • stddev The standard deviation of the distribution. Defaults to 1.0.

Function thrust::random::normal_distribution::normal_distribution

explicit _CCCL_HOST_DEVICE normal_distribution(const param_type & parm); This constructor creates a new normal_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 mean and standard deviation) of the distribution.

Function thrust::random::normal_distribution::reset

_CCCL_HOST_DEVICE void reset(); Calling this member function guarantees that subsequent uses of this normal_distribution do not depend on values produced by any random number generator prior to invoking this function.

Function thrust::random::normal_distribution::operator()

template <typename UniformRandomNumberGenerator> _CCCL_HOST_DEVICE result_type operator()(UniformRandomNumberGenerator & urng); This method produces a new Normal random integer drawn from this normal_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::normal_distribution::operator()

template <typename UniformRandomNumberGenerator> _CCCL_HOST_DEVICE result_type operator()(UniformRandomNumberGenerator & urng,   const param_type & parm); This method produces a new Normal random integer as if by creating a new normal_distribution from the given param_type object, and calling its operator() method with the given UniformRandomNumberGenerator as a source of randomness.

Function Parameters:

  • urng The UniformRandomNumberGenerator to use as a source of randomness.
  • parm A param_type object encapsulating the parameters of the normal_distribution to draw from.

Function thrust::random::normal_distribution::mean

_CCCL_HOST_DEVICE result_type mean() const; This method returns the value of the parameter with which this normal_distribution was constructed.

Returns: The mean (expected value) of this normal_distribution's output.

Function thrust::random::normal_distribution::stddev

_CCCL_HOST_DEVICE result_type stddev() const; This method returns the value of the parameter with which this normal_distribution was constructed.

Returns: The standard deviation of this uniform_real_distribution's output.

Function thrust::random::normal_distribution::param

_CCCL_HOST_DEVICE param_type param() const; This method returns a param_type object encapsulating the parameters with which this normal_distribution was constructed.

Returns: A param_type object encapsulating the parameters (i.e., the mean and standard deviation) of this normal_distribution.

Function thrust::random::normal_distribution::param

_CCCL_HOST_DEVICE void param(const param_type & parm); This method changes the parameters of this normal_distribution using the values encapsulated in a given param_type object.

Function Parameters: parm: A param_type object encapsulating the new parameters (i.e., the mean and variance) of this normal_distribution.

Function thrust::random::normal_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 normal_distribution can potentially produce.

Returns: The lower bound of this normal_distribution's half-open interval.

Function thrust::random::normal_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 normal_distribution's half-open interval.