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 : algorithms


Answers 1


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.

Ross Millikan
Ross Millikan
October 21, 2018 20:09 PM

Related Questions


Algorithm for Converting Rational Into Surreal Number

Updated November 09, 2017 04:20 AM

Complexity of subset-generation algorithm

Updated August 09, 2015 20:08 PM

Analysis for Karatsuba algorithm for multiplication

Updated September 14, 2017 15:20 PM

How to derive algorithm recurrence?

Updated October 10, 2017 02:20 AM

Approximate Factorization of a Natural Number

Updated November 21, 2017 21:20 PM