Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.0.0 - 日本語

Change language to:
English - Français - Português - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
See the recommended documentation of this function

Scilabヘルプ >> Elementary Functions > elementarymatrices > rand

rand

乱数生成

呼び出し手順

r = rand()

r = rand(m1,m2,...)

r = rand(m1,m2,...,key)

r = rand(x)

r = rand(x,key)



s = rand("seed")

rand("seed",s)



rand(key)

key = rand("info")

引数

m1, m2, ...

整数, ランダム行列rの大きさ.

key

文字列, 乱数の分布 (デフォルト key="uniform"). 利用可能な値は "uniform" および "normal"です.

x

実数または複素数の行列. 実数または複素数の内容とその次元のみが処理されます.

r

m1 x m2 x... ランダムなエントリを有するdoubleの実数配列.

s

1行1列double行列, 整数値, 正, シード (デフォルト s=0).

説明

この関数の目的は,実数または複素数のランダムなエントリを有するdoubleの行列 を返すことです. 入力引数に依存して,この関数はdoubleのランダム行列を返したり,または, 乱数の分布を取得または設定したり, 乱数生成器のシードを取得または設定したりできます.

乱数生成器

r=rand()

乱数1個を有する1行1列double行列を返します.

r=rand(m1,m2)

は, 次元が m1m2列のランダム行列です.

r=rand(m1,m2,..,mn)

は,次元がm1 x m2,.. x mn のランダム行列を返します.

r=rand(a)

は,aと同じ大きさのランダム行列を返します. aが実数行列の場合, rは実数, aが複素数行列の場合, rは複素数です.

乱数の分布の変更

入力引数key は乱数生成器の分布を設定します.

rand("uniform")

乱数生成器が一様分布の乱数生成器に 設定されます.乱数は(0,1)の範囲の一様分布となります.

rand("normal")

乱数生成器がガウス乱数生成器(平均0,分散1)に設定されます.

key=rand("info")

カレントの乱数生成器の型("uniform" または "normal")を返します.

シートの取得または設定

乱数生成器のシードを取得または設定することが可能です.

s=rand("seed")

カレントのシードの値を返します.

rand("seed",s)

シードをnに設定します. (デフォルトでは, 最初のコールでs=0 ).

以下の例では, 様々な分布を有するランダムdoubleを生成します.

// Get one random double (based on the current distribution)
r=rand()
// Get one 4-by-6 matrix of doubles (based on the current distribution)
r=rand(4,6)
// Get one 4-by-6 matrix of doubles with uniform entries
r=rand(4,6,"uniform")
// Produce a matrix of random doubles with the same size as x
x=rand(4,4);
r=rand(x,"normal")
// Produce a 2-by-2-by-2 array of random doubles
r=rand(2,2,2)

以下の例では, randにより生成された 数の分布を変更します. まず正規分布を作成した後, 一様分布 [0,1)を作成します.

// Set the rand generator to normal
rand("normal")
r=rand(4,6)
// Get the current distribution
key=rand("info")
// Set the rand generator to uniform
rand("uniform")
r=rand(4,6)
key=rand("info")

以下の例では,正規分布の2行3列のdouble複素数行列を作成します.

// Produce a 2-by-3 matrix of random complex doubles
x=rand(2,3)+%i*rand(2,3)
// Produce a matrix of random complex doubles with
// normal entries and the same size as x
r=rand(x,"normal")

以下の例では, randにより生成された一様分布の数値をプロットします.

r=rand(1000,1,"uniform");
scf();
histplot(10,r);
xtitle("Uniform numbers from rand","X","Frequency")

以下の例では, randにより生成された標準正規分布の数値をプロットします.

r=rand(1000,1,"normal");
scf();
histplot(10,r);
xtitle("Normal numbers from rand","X","Frequency")

予測可能または予測困難な数を取得

"uniform" 擬似乱数生成器は, 範囲(0,1)において独立して一様分布する 数を再現することを目的とする決定論的数列です.

再現可能なシミュレーションを行うには, 数列がセッション間で同じであるように,生成器の初期シードをゼロにします. 言い換えると, rand()により生成される最初の数は, 常に 0.2113249, 0.7560439, ... となります.

いくつかのケースでは, より予測しくい数列を出力するように生成器のシードを初期化したい場合があります. この場合,以下のようにgetdate関数の出力で 初期化することができます:

n=getdate("s");
rand("seed",n);

生成器

"uniform" 乱数生成器は "Urand, A Universal Random Number Generator" において Michael A. Malcolm, Cleve B. Moler, Stan-Cs-73-334, January 1973, Computer Science Department, School Of Humanities And Sciences, Stanford University により記述されています.

これは,以下の形式の線形共役生成器です :

ただし,定数を以下に示します

著者によれば,この生成器はフルレングス生成器であり, つまり,周期はです.

"normal" 乱数生成器は Box-Muller 法に 基づいており, 一様乱数のソースは Urand です.

生成器の統計的品質

より長い周期とより良い統計的特性を有するという意味で, より優れた乱数生成器が grand関数で利用可能です. 乱数の品質が問題となる場合,代わりに grand 関数を検討するべきです. 更に,grand にはより多くの機能があります.

参照

  • grand — 乱数生成器
  • ssrand — 乱数生成器
  • sprand — ランダム疎行列
Report an issue
<< ones elementarymatrices repmat >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 14 15:10:27 CET 2017