in reply to Re: Function over all letters in a string
in thread Function over all letters in a string

D'oh and d'oh. And indeed, it makes little sense to do this in Perl; in C, it would make more sense if performance was an issue. It simply struck me as inelegant to call rand over and over but throw away all but one digit of its return value on every invocation.

Another way not to throw away digits might be something like

$_ = 'dogcatfood'; my $l = length; my $r = sprintf "%${l}.0f\n", rand (10 ** $l);
but that will not work for strings beyond a few hundred characters where 10^length($str) leaves the floating point range ceiling.

Makeshifts last the longest.