Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: RFC: Kinda pseudo-shuffle using sort

by bliako (Monsignor)
on Mar 16, 2021 at 08:50 UTC ( [id://11129748]=note: print w/replies, xml ) Need Help??


in reply to RFC: Kinda pseudo-shuffle using sort

Upd.: P.S. Note time complexity difference: mergesort is O(N log N), Fisher-Yates shuffle is O(N).

I would consider this as a major deterrent. As well as the point made by the other answers.

Since you touched the subject of unorthodox shuffles, perhaps you also want to consider shuffling by converting the array into a hash and back again. For example:

my $pseudoshuffle_with_hash = sub { my( $ref_array ) = shift; @{ $ref_array } = keys %{ {map { $_ => undef } @{ $ref_array }} }; };

bw, bliako

Replies are listed 'Best First'.
Re^2: RFC: Kinda pseudo-shuffle using sort
by rsFalse (Chaplain) on Mar 16, 2021 at 09:29 UTC
    Nice alternative!

    Though it can be used with simple arrays only (containing text and numbers, not references).

    I did the same "histogram" here with '$pseudoshuffle_with_hash'. And I'm getting different results every time, because 'srand(CONST)' doesn't influence hash. But outputs are similar. Kinda symmetric. I paste here two runs:

    3) A A A . . . C C C C C . . . . . E E E . . . G G G G G . . . . . . . . +. . I I I I I A A A A A . . . C C C C C C C C C C E E E . . . . . G G G G G I I I I +I I I I I A A A . . . . . C C C C C . . . . . E E E E E . . . . . . . . . . . . +I I I I I A A A A A . . . . . . . . . . . . . . E E E E E . . . . . G G G G G G +G G G A A A A A A A A A A . . . . . E E E E E . . . . . . . . . G G G G G G +G G G G A A A A A . . . . . . . . . . . . . . . . . . E E E E E E E E E E . . +. . . A A A . . . C C C C C . . . . . E E E . . . G G G G G . . . . . . . . +. I I I I I A A A A A . . . C C C C C C C C C C E E E . . . . . G G G G G I I I I +I I I I I A A A . . . . . C C C C C . . . . . E E E E E . . . . . . . . . . . . +. I I I I I
    3) A A A A A . . . C C C . . . E E E E E . . . G G G G G . . . . . I I I +I I I I I I I A A A A A . . . . . . . C C C C C C C C . . . . . E E E E E . . . . . +. . . . . . . . . . . . C C C C C C C . . . . . . . . . . G G G G G G G G G . . +. . . A A A A A . . . C C C . . . . . E E E E E . . . . . . . . . . I I I I +I I I I I I A A A A A A A A A A . . . . . E E E E E E E E E E . . . . . G G G G G +G G G G A A A A A . . . C C C . . . . . E E E E E . . . . . . . . . . I I I I +I I I I I . . . . . . . C C C C C C C . . . . . . . . . . G G G G G G G G G G . +. . . . A A A A A . . . . . . . C C C C C C C . . . . . E E E E E . . . . . . +. . . . A A A A A . . . C C C . . . E E E E E . . . G G G G G . . . . . I I I +I I I I I I

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11129748]
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: (5)
As of 2024-03-29 10:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found