title: How to deterministically map sequential integers to uniformly distributed doubles
body: <p>I am receiving a sequence of roughly sequential integers (coming from a database key), and I want to map each integer to a double between 0 and 1 in a deterministic way, so that the result set of all the doubles be (close to) uniformly distributed. This should ideally be true even after only a small number of integers have been received.</p>
  
  <p>The mapping needs to be deterministic because it can happen multiple times for each integer (on multiple different machines), and the resulting double should be the same each time the mapping occurs.</p>
  
  <p>e.g. What should the function mapToDouble look like below?</p>
  
  <pre><code>final int start = 100000;
  final int size = 2000;
  final double[] results = new double[size];
  
  for (int i = 0; i &lt; size; i++) {
      results[i] = mapToDouble(i + start)
  }
  
  // results is uniformly distributed
  </code></pre>
  
  <p>The best approach I can think of so far is something like:</p>
  
  <pre><code>double mapToDouble(final int i) {
          final String s = new StringBuilder().append(i).append(".0").reverse().toString();
          return new Double(s);
      }
  </code></pre>
  
  <p>which is approximately uniformly distributed for the most significant bits with a relatively small sample size, but can be skewed for the less significant bits.</p>