I discovered something strange with the generation of random numbers using Java's Random class. Basically, if you create multiple Random objects using close seeds (for example between 1 and 1000) the first value generated by each generator will be almost the same, but the next values looks fine (i didn't search further).
Here are the two first generated doubles with seeds from 0 to 9 :
- 0 0.730967787376657 0.24053641567148587
- 1 0.7308781907032909 0.41008081149220166
- 2 0.7311469360199058 0.9014476240300544
- 3 0.731057369148862 0.07099203475193139
- 4 0.7306094602878371 0.9187140138555101
- 5 0.730519863614471 0.08825840967622589
- 6 0.7307886238322471 0.5796252073129174
- 7 0.7306990420600421 0.7491696031336331
- 8 0.7302511331990172 0.5968915822372118
- 9 0.7301615514268123 0.7664359929590888
And from 991 to 1000 :
- 991 0.7142160704801332 0.9453385235522973
- 992 0.7109015598097105 0.21848118381994108
- 993 0.7108119780375055 0.38802559454181795
- 994 0.7110807233541204 0.8793923921785096
- 995 0.7109911564830766 0.048936787999225295
- 996 0.7105432327208906 0.896658767102804
- 997 0.7104536509486856 0.0662031629235198
- 998 0.7107223962653005 0.5575699754613725
- 999 0.7106328293942568 0.7271143712820883
- 1000 0.7101849056320707 0.574836350385667
And here is a figure showing the first value generated with seeds from 0 to 100,000.
First random double generated based on the seed :
I searched for information about this, but I didn't see anything referring to this precise problem. I know that there is many issues with LCGs algorithms, but I didn't know about this one, and I was wondering if this was a known issue.
And also, do you know if this problem only for the first value (or first few values), or if it is more general and using close seeds should be avoided?
Thanks.
long
ordouble
as a result.