in reply to Re^2: A little golfing challenge: replace digits by random letters
in thread A little golfing challenge: replace digits by random letters

Hello there Discipulus, grazie for the alerts and for fixing the quotes issue serving me my own medicine.

The duplicates are because you ran it too fast! You need to run this code once a second or slower. The universe needs some time to settle ... i.e. the RNG seeds on time whose granularity is the second.

However, here is a version which seeds on something different:

echo '01234567890123456789' | perl -pe '$s=time+join "",{}=~/(\d+)/g;s +/(.)/srand $s;rand for 0..$1;chr(ord("a")+rand 26)/ge'

More characters than expected I have not observed.

This test may be useful for others too:

echo '01234567890123456789' | perl -MTest::More -pe ' my $inp = $_; my $L = length($inp); my $N = 100; # number of trials $nt=0; my %previous = (); for(1..$N){ my $tmp = $inp; my $s = join "$_", {} =~ /(\d+)/g; # because ... $tmp =~ s/(.)/srand $s;rand for 0..$1;chr(ord("a")+rand 26)/ge +; $previous{$tmp} = 1; ok(length($tmp)==$L, "length of conversion (".length($tmp).") +equals expected ($L)."); $nt++; } ok(scalar(keys %previous)==$N, ($N-scalar(keys %previous))." duplicate +s among $N trials"); $nt++; done_testing($nt); '