What you want is a perfect hash function, that is inexpensive in computing time?

Why not ask for something simple, like a perpetum mobile? :-)

The $seed $input is the place in the original list? Maybe permutation encryption algorithms? But to keep them below $max...?

Update: If you could keep $max to a power of 2, you could maybe XOR with a constant? (Update2: The $seed (constant) would also have to be as many bits as $max.)

Code example for Update (n.b. $max must be 2^X):

my $max = 8; my $list = [10, 20, 30, 40, 50, 60, 70, 80]; for(my $seed = 0; $seed < $max; $seed++) { print "With seed $seed: "; for(my $i = 0; $i < @$list; $i++) { my $place = get_rand($i, $seed); print "$place:", $list->[$place], " "; } print "\n"; } sub get_rand { my($item, $seed) = @_; return $item ^ $seed; } __END__ # ------------------------------------------- # output: With seed 0: 0:10 1:20 2:30 3:40 4:50 5:60 6:70 7:80 With seed 1: 1:20 0:10 3:40 2:30 5:60 4:50 7:80 6:70 With seed 2: 2:30 3:40 0:10 1:20 6:70 7:80 4:50 5:60 With seed 3: 3:40 2:30 1:20 0:10 7:80 6:70 5:60 4:50 With seed 4: 4:50 5:60 6:70 7:80 0:10 1:20 2:30 3:40 With seed 5: 5:60 4:50 7:80 6:70 1:20 0:10 3:40 2:30 With seed 6: 6:70 7:80 4:50 5:60 2:30 3:40 0:10 1:20 With seed 7: 7:80 6:70 5:60 4:50 3:40 2:30 1:20 0:10

In reply to Re: Random 1-1 mapping by BerntB
in thread Random 1-1 mapping by tomazos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.