- rand EXPR
- rand
-
Returns a random fractional number greater than or equal to
0and less than the value of EXPR. (EXPR should be positive.) If EXPR is omitted, the value1is 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 10Notes:
注意:
-
Calling
randautomatically calls srand unless srand has already been called.randを呼び出すと、srand が既に呼ばれている場合以外は、自動的に srand 関数を呼び出します。 -
Currently EXPR with the value
0is 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 thedrand48pseudorandom number generator to generate random numbers. As a PRNGdrand48should be sufficient for most non-cryptographic needs. If you need cryptographic random numbers check CPAN for crypto safe alternatives.Perl v5.20.0 から、
rand()は乱数の生成にdrand48疑似乱数生成器を 使います。 疑似乱数生成器として、drand48はほとんどの非暗号的な用途に対して 充分です。 暗号的乱数が必要な場合は、暗号的に安全な代替案について CPAN を チェックしてください。
- Security:
-
randis 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 モジュールが 作者によって暗号学的に安全であることを目的とした乱数生成器を 提供しています:
-