Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Random 1-1 mapping

by Zaxo (Archbishop)
on May 28, 2006 at 18:10 UTC ( [id://552200]=note: print w/replies, xml ) Need Help??


in reply to Random 1-1 mapping

Since an array has the factorial of its element count possible orders, your $input must have that range to obtain a 1-1 relation. Are you sure that so stringent a requirement is needed?

Check out List::Util::shuffle(). It may be good enough for what you want.

You won't want to keep C++ comments in your perl, and prototypes are usually not desirable. See perltrap.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: Random 1-1 mapping
by tomazos (Deacon) on May 28, 2006 at 18:37 UTC
    Fixed comments. Been writing in both languages and can now write in neither.

    $input is just a scalar. It has the range 0..$max. I don't see where a factorial of the count comes in.

    The idea is:

    shuffle(42, 10, 0) == 6 shuffle(42, 10, 1) == 1 shuffle(42, 10, 2) == 5 shuffle(42, 10, 3) == 8 shuffle(42, 10, 4) == 3 shuffle(42, 10, 5) == 4 shuffle(42, 10, 6) == 9 shuffle(42, 10, 7) == 2 shuffle(42, 10, 8) == 7 shuffle(42, 10, 9) == 0

    ?

    -Andrew.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2024-04-25 00:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found