Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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

by BrowserUk (Patriarch)
on Feb 10, 2019 at 11:24 UTC ( #1229705=note: print w/replies, xml ) Need Help??

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

Not a perfect shuffle, but close (enough?) and much shorter:

perl -M5';$x=join"",sort{rand()<rand}a..z' -pe 'eval"tr/0-9/$x/"' input.txt

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

Replies are listed 'Best First'.
Re^2: A little golfing challenge: replace digits by random letters
by bliako (Monsignor) on Feb 10, 2019 at 13:02 UTC

    half-blind-sort is a great idea (and so is {rand()<rand} ).

    Couldn't resist sort{rand(2)-1} as it's shorter by 2 and truer blind.

    Update/Correction: as vr rightly notes, int(rand(2)-1) is constantly 0!!! Because sort expects an integer back from the comparison BLOCK and int()'ing rand(2)-1 leaves just 0 :(. So, both these compensate for that bug and are uniformly random too: sort{rand(6)-4} and sort{1-rand(3)%3}

      Perhaps sort{rand(2)-1} (in effect, same as sort{0}) is somewhat too deterministic :). But

      $ perl -E 'say sort{rand 2}a..z'

      produces random enough strings, and is shorter.

        ai! indeed it is. got bitten by int. This is uniformly random sort{rand(6)-4} and so is this sort{1-rand(3)%3}

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2022-01-17 02:24 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (50 votes). Check out past polls.