-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On 19 Aug 2004, at 18:04, Luke Palmer wrote:
The one in Perl 5 that stands out most was the cause for the only patch
I ever sent to p5p: the rand function.  "rand $x" will give you a
uniformly distributed random number in [0, $x) for any $x EXCEPT 0.  If
you say "rand 0", it gives you a random number between 0 and 1, which
was supposed to be What I Meant.  That led to code like this (Perl6ized
as usual):

my $num = $param == 0 ?? 0 : rand $param;

my $num = $param == 0 ?? 0 :: rand $param;

surely?

Repeating the test that it did itself, just to get consistent behavior.
We must be careful not to repeat mistakes like this in the design of
Perl 6 [1].

It would be nice if rand behaved a bit more sanely in Perl 6. I can understand the reasoning for making rand 0 produce between 0 and 1, but that doesn't mean I have to like it. If that behaviour is required, then rand undef; would behave as expected (call with no parameters to get [0, 1), with one param to get [0, $param) ), but really if you want a random number between 0 and 1 why aren't you calling rand 1?


Feels like a Cism. Ick.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (Darwin)

iD8DBQFBJbRx0UvYjCBpIlARAjV2AJ0TSuchOHcVMqg3HUPLJ6G5zhnRYwCfQ/26
C6DCRHq0BjxqX4eH5vUeWwk=
=ctmb
-----END PGP SIGNATURE-----




Reply via email to