Created attachment 87644 [details]
The RAND() function of Calc was fixed on bug 33365. Yet the same bug is present with the "Rnd" random number generation function of BASIC as well.
Even with as few records as 1000, the "random" numbers repeat themselves several times. Test document (ODS) with test macro attached.
1. Open the attached document
2. Click the "Generate" button to (re-)generate 1000 numbers. Wait for "Generation Status" to change from "Started..." to "Ready"
2. Cell D1 shows 1.00000000 (i.e. no repetition of values in the B column)
2. Value of D1 always bigger than 1.00000000 (between 1.02200000 and 1.04400000 on just a few tests), due to many repeated values in the B column. (Column C shows how many times a number is repeated.)
WinXP Home 32 bit, LO 220.127.116.11 release
- The issue does not occur on with the test file attached to bug 33365, which tests the RAND() function of Calc. To achieve comparable results, my attached file is based on that file and uses the same evaluation methods.
- Usage of the "Randomize" generator initialization function before the first "Rnd" usage does not work around the problem.
- Calc RAND() fix commit http://cgit.freedesktop.org/libreoffice/core/commit/?id=8450a99c744e9005f19173e4df35d65640bcf5c4 says that seed() "initialises the state of the global random number generator" and it "should only be called once at the start of the main programme". So, maybe the latter information should be added to the description of the "Randomize" function in LO help. Because, according to that information, additional later seeding of the random number generator would make it loose the entropy it has accumulated so far. (Assuming it does accumulate it continuously since application start.)
On a side note: The preliminary release notes of LO 4.2 under https://wiki.documentfoundation.org/ReleaseNotes/4.2#Calc state that a new Calc functionality has been added, to fill cell(s) with a random number(s) via Menu -> Edit -> Fill -> Random Number... I couldn't find the related implementation bug report, but it might need to be checked too, as to whether it uses the new generation method similarly to RAND() in Calc. Because there doesn't seem to be one central PRNG in LO; with different components using different implementations.
(In reply to comment #1)
> On a side note: The preliminary release notes of LO 4.2 under
> https://wiki.documentfoundation.org/ReleaseNotes/4.2#Calc state that a new
> Calc functionality has been added, to fill cell(s) with a random number(s)
> via Menu -> Edit -> Fill -> Random Number... I couldn't find the related
> implementation bug report, but it might need to be checked too, as to
> whether it uses the new generation method similarly to RAND() in Calc.
> Because there doesn't seem to be one central PRNG in LO; with different
> components using different implementations.
Found it, its part of bug 66477: http://cgit.freedesktop.org/libreoffice/core/commit/?id=5c05b1cabcf7f6a7f490ae6fc4bc145e75229752
P.S.: In case it matters for this bug: I tested with an Asus EeePC netbook, with an Intel Atom N450 CPU. (Don't know if it has a built-in CPU RNG.)
Thomas Arnhold committed a patch related to this issue.
It has been pushed to "master":
fdo#70474: Random number generation weak with Rnd in BASIC
The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
Affected users are encouraged to test the fix and report feedback.