  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # How to deterministically map sequential integers to uniformly distributed doubles  » java » How to deterministically map sequential integers to uniformly distributed doubles

By : Asep Saepuloh
Date : October 23 2020, 08:10 PM
around this issue Sure, you could use Linear Congruential Generator to do the mapping. Basically, LCG with proper parameters satisfying Hull–Dobell Theorem, uniquely maps any integer in [0...264) range into another one in the [0...264) range, good bits chopper so to speak. Doubles won't be unique, not enough of them in the [0...1) range.
Java pseudocode (sorry, did Java long time ago, assumed Java 8 with Long here) code :
``````static final long a = Long.parseUnsignedLong("2862933555777941757"); // values taken from https://nuclear.llnl.gov/CNP/rng/rngman/node4.html
static final long c = Long.parseUnsignedLong("3037000493");

double mapToDouble(final int i) {
long seed = (long)i;
long mapl = a * seed + c; // should do wraparound automatically, or use Long.remainderUnsigned
double x  = (x >>> 11) * 0x1.0p-53; // see http://xoshiro.di.unimi.it/
return x;
}
`````` ## What's the standard way for getting uniformly distributed random integers in C++?

By : Jake123
Date : March 29 2020, 07:55 AM
it should still fix some issue Boost provides many tools for random number generation. For uniform distributions you have this one:
http://www.boost.org/doc/libs/1_49_0/doc/html/boost/random/uniform_real_distribution.html
code :
``````#include <random>
#include <iostream>
int main()
{
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(1, 6);
for(int n=0; n<10; ++n)
std::cout << dis(gen) << ' ';
std::cout << '\n';
}
`````` ## How to make a regression line in R using a normally distributed error and a uniformly distributed random variable

By : user3261295
Date : March 29 2020, 07:55 AM
wish of those help Arithmetic operators in R work on vectors, so you don't need the loops at all:
code :
``````y <- 5 + 3 * xvals + evals
``````
``````xvals <- runif(n = 100, min = -1, max = 1)
evals <- rnorm(n = 100, mean = 0, sd = 1)
y <- 5 + 3 * xvals + evals

print(y)
plot(xvals, y)
``````
``````y <- append(y, 5 + 3*x + e)
`````` ## A space efficient data structure to store and look-up through a large set of (uniformly distributed) Integers

By : Tuciiii
Date : March 29 2020, 07:55 AM
hope this fix your issue While Jon Skeet's answer gives good savings for a small investment, I think you can do better. Since your numbers are fairly even distributed, you can use an interpolating search for faster lookups (roughly O(log log N) instead of O(log N)). For a million items, you can probably plan on around 4 comparisons instead of around 20.
If you want to do just a little more work to cut the memory (roughly) in half again, you could build it as a two-level lookup table, basically a sort of simple version of a trie. ## How to get pseudo-random uniformly distributed integers in C good enough for statistical simulation?

By : mcz
Date : March 29 2020, 07:55 AM
Does that help rand % N does not work; it skews your results unless RAND_MAX + 1 is a multiple of N.
A correct approach is to figure out the largest multiple of N that's smaller than RAND_MAX, and then generate random numbers until it's less than that value. Only then should you do the modulo operation. This gives you a worst-case rejection ratio of 50%. ## Uniformly distributed pseudorandom integers inside CUDA kernel

By : user4918081
Date : March 29 2020, 07:55 AM
With these it helps I suggest two options within a Kernel:
1) using curand_uniform to obtain a random floating point number from a uniform distribution, then map it to integer interval: 