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

Re: When the Best Solution Isn't

by blakem (Monsignor)
on Sep 23, 2002 at 03:01 UTC ( #199989=note: print w/replies, xml ) Need Help??


in reply to When the Best Solution Isn't

@random = sort { .5 <=> rand(1) } @array; # DO NOT USE THIS!
Aside from not being a fair shuffle (8 paths mapped to 6 end states) I believe it can actually cause older perls to dump core.

Sorting assumes a transitive ranking function... If A > B and B > C then A > C. Returning random numbers for your comparison results wont comply with this requirement, and can wreak havoc depending on the internal sorting implementation.

-Blake

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2019-11-13 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (74 votes). Check out past polls.

    Notices?