As stated above, you're good to go as long as max % prime != 0:
use strict; use warnings; my ($seed, $prime, $max, $input, $result); $seed = 8; for $prime (2,3,5,7,11,13,17,19,23) { for $max (20..30) { next if $max % $prime == 0; my %hash; for $input (0..($max-1)) { $result = ($prime * $input + $seed) % $max; $hash{$result}++; } print "$prime $max : "; print join '', values %hash, "\n"; } }
All you need to guarantee this is a sufficiently large prime so that it's always going to be larger than sqrt(max) (but not equal to max itself).
use strict; use warnings; my (@arr, $seed, $max, $prime, $input, $result); @arr = 1..10; $seed = 5; $max = $#arr+1; $prime = 65521; for $input (0..($max-1)) { $result = ($prime * $input + $seed) % $max; print $arr[$result], " "; }
The hard part though, since I assume you're doing this in assembly or a low level language, will be making sure that none of the basic mathematical operations go out of bounds.

In reply to Re: Random 1-1 mapping by TedPride
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.