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

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -