# matching algorithm

by Realin Theoryin   Last Updated October 21, 2018 20:20 PM

I have a finite number (around 30,000) of non contiguous integers with values ranging from 1 to, say, 10 billion

I want to spread each of the 30,000 numbers randomly in the number range of 1 to 16 million (I'm trying to give each original number an RGB colour value) so that each original number always get the same value in the range 0 to 16 million.

e.g. 10 is always 323,242 or 123,523,534 is always 242

I think it's something to do with hash functions..but would welcome any help

Tags :

The simplest is to multiply each integer by $$\frac {16,000,000}{10,000,000,000}$$. This probably does not satisfy your definition of random. Another approach is to multiply it by some large prime, say with $$30$$ digits and take the $$\bmod 16,000,000$$. That might be random enough for you. You could also feed it to some hash algorithm and take the result $$\bmod 16,000,000$$. That will -feel random but still give you repeatability.