Boost 隨機數庫:變種生成器

變種生成器用來組合隨機數生成器和隨機分佈。Boost.Random 提供了大量的 生成器分佈

variate_generator 類模板

概覽

#include <boost/random/variate_generator.hpp>

template<class Engine, class Distribution>
class variate_generator
{
public:
  typedef Engine engine_type;
  typedef Distribution distribution_type;
  typedef typename Distribution::result_type result_type;

  variate_generator(Engine e, Distribution d);

  result_type operator()();
  template<class T>
  result_type operator()(T value);
  
  engine_value_type& engine();
  const engine_value_type& engine() const;

  result_type min() const;
  result_type max() const;
};

描述

variate_generator 類模板的實例是 數字生成器 的模型。

模板參數 Engine 的實參應當具有形式 U, U& 或 U*,其中 U 為一均勻隨機數生成器。成員 engine_value_type 則為 U (不是其指針或引用類型)。

variate_generator 的專門化滿足 CopyConstructible 的需求,也滿足 Assignable 的需求,除非參數 Engine 為 U& 的形式。

本節給出的所有函數的複雜度都是常數的。除構造函數外,均不拋出異常。

    variate_generator(engine_type eng, distribution_type d)

效果:用均勻隨機數生成器 eng 和隨機分佈 d 構造一 variate_generator 對象。
拋出:Engine 或 Distribution 的複製構造函數所拋出的異常。

    result_type operator()()

返回: distribution()(e)
Notes: The sequence of numbers produced by the uniform random number generator e, se, is obtained from the sequence of numbers produced by the associated uniform random number generator eng, seng, as follows: Consider the values of numeric_limits<T>::is_integer for T both Distribution::input_type and engine_value_type::result_type. If the values for both types are true, then se is identical to seng. Otherwise, if the values for both types are false, then the numbers in seng are divided by engine().max()-engine().min() to obtain the numbers in se. Otherwise, if the value for engine_value_type::result_type is true and the value for Distribution::input_type is false, then the numbers in seng are divided by engine().max()-engine().min()+1 to obtain the numbers in se. Otherwise, the mapping from seng to se is implementation-defined. In all cases, an implicit conversion from engine_value_type::result_type to Distribution::input_type is performed. If such a conversion does not exist, the program is ill-formed.

    template<class T> result_type operator()(T value)

返回: distribution()(e, value)e 的語義已在 operator()() 的描述中給出。

    engine_value_type& engine()

返回:相關均勻隨機數生成器的引用。

    const engine_value_type& engine() const

返回:相關均勻隨機數生成器的引用。

    distribution_type& distribution()

返回:相關分佈的引用。

    const distribution_type& distribution() const

返回:相關分佈的引用。

    result_type min() const

前條件: distribution().min()有定義
返回: distribution().min()

    result_type max() const

前條件: distribution().max() 有定義
返回: distribution().max()


Valid HTML 4.01 Transitional

Revised 05 December, 2006

Copyright © 2003-2004 Jens Maurer

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

中文版修訂:2009/1/25

Copyright © 2008 xiaq

在 Boost Software License, Version 1.0 的條款下發佈。(參看文件 LICENSE_1_0.txt 或在線副本 http://www.boost.org/LICENSE_1_0.txt)