L
Larry
Just thought I'd put out a warning for y'all to check your code against
a nasty "gotcha"
The 2 examples
int(rand() * 256)
and
int(rand * 256)
are *not* the same!! The second example is *not* what you want (unless
you want 0 all the time). Apparently the second example is actually
passing the typesplat "* 256" of all things (as if there's a chance
that's what anyone would want) into "rand" which somehow ends up the
same as rand(), so the second example is actually doing:
int(rand())
which explains the constant zeros.
Horrifyingly, I was using this code in an *encryption* routine with
results about what you'd expect. Thankfully, I hapenned to notice it
fairly quickly (just because I'm the type that would nose around inside
a supposedly encrypted file just to see if it smells normal... it most
decidedly did not)
This is not the sort of DWIM behavior I normally expect from Perl!
Ahh, well, perfection is not for this world. But... damn!!
a nasty "gotcha"
The 2 examples
int(rand() * 256)
and
int(rand * 256)
are *not* the same!! The second example is *not* what you want (unless
you want 0 all the time). Apparently the second example is actually
passing the typesplat "* 256" of all things (as if there's a chance
that's what anyone would want) into "rand" which somehow ends up the
same as rand(), so the second example is actually doing:
int(rand())
which explains the constant zeros.
Horrifyingly, I was using this code in an *encryption* routine with
results about what you'd expect. Thankfully, I hapenned to notice it
fairly quickly (just because I'm the type that would nose around inside
a supposedly encrypted file just to see if it smells normal... it most
decidedly did not)
This is not the sort of DWIM behavior I normally expect from Perl!
Ahh, well, perfection is not for this world. But... damn!!