in reply to Random 1-1 mapping
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Random 1-1 mapping
by tomazos (Deacon) on May 28, 2006 at 18:54 UTC | |
by blokhead (Monsignor) on May 28, 2006 at 21:26 UTC |