- rand EXPR
- rand
-
Returns a random fractional number greater than or equal to
0
and less than the value of EXPR. (EXPR should be positive.) If EXPR is omitted, the value1
is used.0
以上 EXPR の値 未満 の小数の乱数値を返します。 (EXPR は正の数である必要があります。) EXPR が省略されると、1
が使われます。my $num1 = rand(); # Random float at least 0 and below 1 my $num2 = rand(7); # Random float at least 0 and below 7 my $num3 = int(rand(10)); # Random integer at least 0 and below 10
Notes:
注意:
-
Calling
rand
automatically calls srand unless srand has already been called.rand
を呼び出すと、srand が既に呼ばれている場合以外は、自動的に srand 関数を呼び出します。 -
Currently EXPR with the value
0
is special-cased as1
. This was undocumented before Perl 5.8.0 and is subject to change in future versions of Perl.現在のところ、EXPR に値
0
をセットすると1
として特別扱いされます。 これは Perl 5.8.0 以前には文書化されておらず、将来のバージョンの perl では 変更される可能性があります。 -
As of Perl v5.20.0
rand()
uses thedrand48
pseudorandom number generator to generate random numbers. As a PRNGdrand48
should be sufficient for most non-cryptographic needs. If you need cryptographic random numbers check CPAN for crypto safe alternatives.As of Perl v5.20.0
rand()
uses thedrand48
pseudorandom number generator to generate random numbers. As a PRNGdrand48
should be sufficient for most non-cryptographic needs. If you need cryptographic random numbers check CPAN for crypto safe alternatives. (TBT)
- Security:
-
rand
is not cryptographically secure. You should not rely on it in security-sensitive situations. As of this writing, a number of third-party CPAN modules offer random number generators intended by their authors to be cryptographically secure, including:rand
は暗号学的に安全ではありません。 セキュリティ的に重要な状況でこれに頼るべきではありません。 これを書いている時点で、いくつかのサードパーティ CPAN モジュールが 作者によって暗号学的に安全であることを目的とした乱数生成器を 提供しています:
-