Movatterモバイル変換


[0]ホーム

URL:


functions /rand
(source,CPAN)
You are viewing the version of this documentation from Perl 5.38.3.View the latest version
#rand EXPR
#rand

Returns a random fractional number greater than or equal to0 and less than the value of EXPR. (EXPR should be positive.) If EXPR is omitted, the value1 is used. Currently EXPR with the value0 is also special-cased as1 (this was undocumented before Perl 5.8.0 and is subject to change in future versions of Perl). Automatically callssrand unlesssrand has already been called. See alsosrand.

Applyint to the value returned byrand if you want random integers instead of random fractional numbers. For example,

int(rand(10))

returns a random integer between0 and9, inclusive.

(Note: If your rand function consistently returns numbers that are too large or too small, then your version of Perl was probably compiled with the wrong number of RANDBITS.)

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:Data::Entropy,Crypt::Random,Math::Random::Secure, andMath::TrulyRandom.

Perldoc Browser is maintained by Dan Book (DBOOK). Please contact him via theGitHub issue tracker oremail regarding any issues with the site itself, search, or rendering of documentation.

The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via thePerl issue tracker, themailing list, orIRC to report any issues with the contents or format of the documentation.


[8]ページ先頭

©2009-2025 Movatter.jp