Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As long as you limit the set of possible output values to the SAME set of values as the operands you are using as operands, then you cannot do any better than addition. Addition, actually, is probably the best possible choice, because it is simplest. (See analysis below) </p> <p>There are 2^64 possible longs, so there are 2 ^ 127 possible unordered pairs of longs, and only 2^64 possible longs for an answer, so the best possible distribution ratio is to have 2^ 63 different pairs that give the same answer, which addition, (with rollover) in fact, will do</p> <p>EDIT: based on comments below.</p> <p>however many (say it's N bits) a long is, there are 2^N different longs, so there are 2^N x 2^N ordered pairs of longs, but for the purposes of this analysis, using two longs x, and y is exactly the same as using y and x (the binary op is assumed to be communitative), so there are 2^ (2N-1) unordered pairs of longs. </p> <p>so using unordered pairs (half as many) there are 2^N x (2^N-1) or 2^ (2N-1) pairs of longs without duplicates. (If N = 64, that's 2^127) So the maximum "distribution" of assignment of answers (from the smaller set of 2^64 longs) to the unordered pairs of operands (the larger set of 2^ 127 pairs) is if they are equally distributed. Thats what addition would do, because for each of possible long in the set of all longs, the sum of it with every other long (with rollover) will be a set of ... every long. </p> <p>the only thing using ordered pairs does is allow you to use a non-communtative operand as well, but then you have to deal with all the cases where the answer is not in the set you are using for operands (like 5/4 )but even if you just assume rounding, the only impact on the analysis is that by using ordered pairs you get 2^2N different pairs of operands, instead of 2^(2N-1).</p> <p>What you might do is limit the set of integers to be used as the operands to less than the square root of the number of possible longs (so if you are using 64 bit longs, limit your input values to 32 bit longs) Then, if you want absolutely no overlap or duplication (No case where A op B = same value as any other C op D), you can use the multiplication operator but for each value X in the smaller set of potential operands, choose the Xth prime number as the multiplicative operand. that way, no matter what two values A and B you randomly pick (from 1 to Max) the operantion would be multiplication of two different primes. This means the set of possible operands has to be smaller than the set of prime numbers equal to or less than the maximum possible value you are using for operand (if it's 64 bit unsigned longs, that 2^64)</p> <p>2nd EDIT: based on yr specific problem, the set of possible operands is limited to the dimensions of a computer screen, considerably less than the number of longs, (no matter what platform you are on) So a very easy and obvious way to guarantee that every pair of possible screen cooridinates will generate a distinct and different seed key is to simply left shift the value of one coordinate sufficiently to guarantee no bitwise overlap with the other coordinate, and then bitwise Or the result with the other coordinate. </p> <p>So if your screen is say, 3000x3000, then long lngVal = (x&lt;&lt;12 | y) would do it with minimal computational overhead as well.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload