Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: A little golfing challenge: replace digits by random letters

by Discipulus (Canon)
on Feb 10, 2019 at 17:45 UTC ( [id://1229732]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1229732]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2024-04-24 00:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found