java - Creating a set of uniformly distributed random numbers -
i have list of n
objects.
insert x
dummy objects randomly placed between real n
objects, spaced between (0, n).
so tried following code.
int[] dummyindexes = new int[x]; int randomstep = n/x * 2; // *2 because mean n/x/2 random random = new random(); int randidx = 0; (int i=0; < x; i++) { randidx += random.nextint(randomstep); dummyindexes[i] = randidx; }
this works alright, although i'm not getting distribution way end of domain n
.
what's better way ?
this ensure have 1 random value between each n/x
randidx = n * / x + random.nextint(n / x) + 1;
Comments
Post a Comment