int(rand() + 1), int(rand()) +1, and hashes
Russ Schnapp
rlssdpm at schnapp.org
Sun Jul 16 09:35:25 CDT 2000
~sdpm~
> A floating number 1.005 is converted into a string and is used as
a hash key.
> Converting a floating number to a string is obviously much slower
than
> converting an int
>
> what's so surprising?
Okay, I'll bite. Here are the code samples again:
> sub randint1 {
> $r1 = int( rand(4) + 1 );
> $h1{$r1}++;
> }
>
> sub randint2 {
> $r2 = int( rand(4) ) + 1;
> $h2{$r2}++;
> }
randint2() ran slower than randing1(), and you're saying that's
because $r2 was a float while $r1 was an int? I need to understand
this. How did adding an integer (1) to the result of an int() generate
a floating result?
...Russ
~sdpm~
The posting address is: san-diego-pm-list at hfb.pm.org
List requests should be sent to: majordomo at hfb.pm.org
If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:
unsubscribe san-diego-pm-list
If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.
More information about the San-Diego-pm
mailing list