/* -*- MaTX -*- * * 【名前】 * rand() - 一様乱数 * * 【形式】 * y = rand() * Real y; * * Y = rand(n) * Array Y; * Integer n; * * Y = rand(m,n) * Array Y; * Integer m,n; * * Y = rand(X) * Array Y; * (Matrix|Array) X; * * s = rand("seed"); * Integer s; * * p = rand("seed", s); * Integer p; * Integer s; * * 【機能説明】 * rand()は,区間(0,1)に一様に分布する乱数を生成する。整数 n について, * rand(n)は n x n の一様乱数配列を返す。rand(m,n) は,m x n の一様乱数 * 配列を返す。X が行列のとき,rand(X) は,X と同じ大きさの一様乱数 * 配列を返す。 * * rand() は疑似乱数に基づき区間 [2^(-53),1-2^(-53)] の浮動小数点を * 生成する。理論的に,生成される乱数の周期は約 2.3 x 10^(18)である。 * * 乱数列は乱数発生器の状態に依存して決定され,乱数発生器の状態は * 種によって変更できる。rand("seed") は一様乱数の種(Integer)を返し, * rand("seed", m) は一様乱数の種を整数 m に設定する。 * * 【例題】 * 1 x 4 の一様乱数配列を生成する。 * * Y = rand(1, 4) * === [Y] : ( 1, 4) === * ( 1) ( 2) ( 3) ( 4) * ( 1) 2.8538089E-01 2.5335818E-01 9.3468531E-02 6.0849689E-01 * * 次の例では,まず乱数発生器の種を調べる。1個の乱数を生成すると種が * 変わることが分かる。種の初期値は 1 である。 * * >> s = rand("seed") * s = 1271983233 * >> y = rand() * y = 0.90342 * >> s = rand("seed") * s = 1776642162 * >> s = rand("seed", 1) * s = 1 * >> y = rand() * y = 0.285381 * * 【アルゴリズム】 * 文献 1, 2 参照。 * * 【関連項目】 * randn() * * 【参考文献】 * [1] William H. Press and Brian P. Flannery and Saul A. Teukolsky * and William T. Veterling, Numerical Recipes in C (The Art of * Scientific Computing), Cambridge University Press, 1988 * * [2] 丹慶 勝市, 奥村 晴彦, 佐藤 俊朗, 小林 誠, * ニューメリカルレシピ・イン・シー, 技術評論社, 1993 */