I made a macro for "Calc" on Open Office, in order to train my little daughter with multiplications. It needs random numbers, and the part which create this numbers looks like this : nouveau: Randomize ch1 = int(10* Rnd + 1) Randomize ch2 = int(10 * Rnd + 1) 'pose la question de la multiplication et attends le réponse Message = "calcule " & ch1 & " x " & ch2 ' Définit le message. Title = "MULTIPLICATION" ' Définit le titre. Defaut = "0" ' Définition de la valeur par défaut. ' Affiche le message, le titre et la valeur par défaut. result = InputBox(Message, Title, Defaut) With Open Office I really obtain two random numbers. With Libre Office (I just begin with it) I systematically have the two same numbers. I tried to add a number at the instruction "Randomize, lique this : Randomize ch1 = int(10* Rnd + 1) Randomize (3) ch2 = int(10 * Rnd + 1) Then the second number was generally different from the first, but did not change ! Worse : I tried to debug the programm with the stop points and the witness(témoin in french), and in these conditions the programs functionned correctly! Thanks for your help BA
take the (3) off the 2nd randomize command
Created attachment 114202 [details] test case I can confirm with LO 4.4.1.2, win7
Bibisect results from 43all 5193ebac92810823540db2b5cf24d33db5ef489c is the first bad commit commit 5193ebac92810823540db2b5cf24d33db5ef489c Author: Bjoern Michaelsen <bjoern.michaelsen@canonical.com> Date: Tue May 20 16:58:37 2014 +0000 source-hash-3558f9c0592b443f20ca1f406198f89a5385767e commit 3558f9c0592b443f20ca1f406198f89a5385767e Author: Julien Nabet <serval2412@yahoo.fr> AuthorDate: Sun May 18 01:14:29 2014 +0200 Commit: Julien Nabet <serval2412@yahoo.fr> CommitDate: Sun May 18 01:14:29 2014 +0200 Looks like it ought to be the below commit within that range. Adding Cc: to thomas-libo@arnhold.org; Could you possibly take a look at this? Thanks (As the user doesn't readily have access to another source of entropy from within Basic, the fact that doing Randomize twice near in time sets the seed to the same value is rather surprising. If it's documented as doing that, a) AOO doesn't do that in practice, and b) we should probably just change the documentation) commit df466d79cb126667cc9d5c108367bfa4f5ce76c8 Author: Thomas Arnhold <thomas@arnhold.org> Date: Tue May 13 22:42:49 2014 +0200 fdo#70474: Random number generation weak with Rnd in BASIC Just reuse the rng functionality. This improves the randomness. Initialize seed with system time if no argument for RANDOMIZE is given. As the help text states: "If Number is omitted, the generator uses the current value of the system timer". Change-Id: I5fa46e8344b2402dff66a8db2449d43e2ca27d6d Reviewed-on: https://gerrit.libreoffice.org/9349 Reviewed-by: Thomas Arnhold <thomas@arnhold.org> Tested-by: Thomas Arnhold <thomas@arnhold.org>
Today I suppressed the second "randomize", and now the macro works normally, with no number repeat.
problem is that when you call Randomize() within the same second it will use the same seed number so the same sequence of random numbers will be generated. btw the same commit that broke this means that you don't actually need to call Randomize() any more, it will be done automatically when you get the first random number. fixed on master
Michael Stahl committed a patch related to this issue. It has been pushed to "master": http://cgit.freedesktop.org/libreoffice/core/commit/?id=564fc483931c0aa2872a33023473c7ac36bfedf1 tdf#90110: basic: fix Randomize statement It will be available in 5.0.0. 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: http://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Michael Stahl committed a patch related to this issue. It has been pushed to "libreoffice-4-4": http://cgit.freedesktop.org/libreoffice/core/commit/?id=0e5aa443f8f603be6e5ad4ddcec12e5b6fbdff8a&h=libreoffice-4-4 tdf#90110: basic: fix Randomize statement It will be available in 4.4.4. 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: http://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Migrating Whiteboard tags to Keywords: (bibisected) [NinjaEdit]