Bug 90110 - The instruction "Randomize" does not operate correctly
Summary: The instruction "Randomize" does not operate correctly
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
4.3.5.2 release
Hardware: Other All
: medium normal
Assignee: Michael Stahl (allotropia)
URL:
Whiteboard: target:5.0.0 target:4.4.4
Keywords: bibisected, bisected, regression
Depends on: 70474
Blocks: 99809
  Show dependency treegraph
 
Reported: 2015-03-19 21:03 UTC by bernadette.adam
Modified: 2016-05-12 19:07 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments
test case (10.73 KB, application/vnd.oasis.opendocument.spreadsheet)
2015-03-20 06:46 UTC, raal
Details

Note You need to log in before you can comment on or make changes to this bug.
Description bernadette.adam 2015-03-19 21:03:10 UTC
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
Comment 1 ObrienDave 2015-03-19 21:16:41 UTC
take the (3) off the 2nd randomize command
Comment 2 raal 2015-03-20 06:46:16 UTC
Created attachment 114202 [details]
test case

I can confirm with LO 4.4.1.2, win7
Comment 3 Matthew Francis 2015-03-21 12:39:26 UTC
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>
Comment 4 bernadette.adam 2015-03-21 20:19:41 UTC
Today I suppressed the second "randomize", and now the macro works normally, with no number repeat.
Comment 5 Michael Stahl (allotropia) 2015-05-19 20:08:52 UTC
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
Comment 6 Commit Notification 2015-05-19 20:09:22 UTC
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.
Comment 7 Commit Notification 2015-05-20 14:04:37 UTC
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.
Comment 8 Robinson Tryon (qubit) 2015-12-17 08:49:32 UTC
Migrating Whiteboard tags to Keywords: (bibisected)
[NinjaEdit]