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

Hello bliako,

apart the typo ( 'a' insted of "a") I see duplicates in you code output and more characters than expected

See it here

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^3: A little golfing challenge: replace digits by random letters
by bliako (Abbot) on Feb 10, 2019 at 19:44 UTC

    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); '