[Libreoffice-commits] core.git: basic/inc basic/source

Thomas Arnhold thomas at arnhold.org
Sat May 17 05:41:25 PDT 2014


 basic/inc/pch/precompiled_sb.hxx |    1 +
 basic/source/runtime/methods.cxx |   13 ++++++-------
 2 files changed, 7 insertions(+), 7 deletions(-)

New commits:
commit df466d79cb126667cc9d5c108367bfa4f5ce76c8
Author: Thomas Arnhold <thomas at 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 at arnhold.org>
    Tested-by: Thomas Arnhold <thomas at arnhold.org>

diff --git a/basic/inc/pch/precompiled_sb.hxx b/basic/inc/pch/precompiled_sb.hxx
index 4c0ba1b..a7cd16b 100644
--- a/basic/inc/pch/precompiled_sb.hxx
+++ b/basic/inc/pch/precompiled_sb.hxx
@@ -29,6 +29,7 @@
 #include <com/sun/star/uno/XInterface.hpp>
 #include <com/sun/star/util/DateTime.hpp>
 #include <comphelper/processfactory.hxx>
+#include <comphelper/random.hxx>
 #include <comphelper/string.hxx>
 #include <cstddef>
 #include <ctype.h>
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index fe2f00d..2e3c375 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -45,6 +45,7 @@
 #include "errobject.hxx"
 
 #include <comphelper/processfactory.hxx>
+#include <comphelper/random.hxx>
 #include <comphelper/string.hxx>
 
 #include <com/sun/star/uno/Sequence.hxx>
@@ -3521,16 +3522,16 @@ RTLFUNC(Randomize)
     {
         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     }
-    sal_Int16 nSeed;
+    int nSeed;
     if( rPar.Count() == 2 )
     {
-        nSeed = (sal_Int16)rPar.Get(1)->GetInteger();
+        nSeed = (int)rPar.Get(1)->GetInteger();
     }
     else
     {
-        nSeed = (sal_Int16)rand();
+        nSeed = (int)time(NULL);
     }
-    srand( nSeed );
+    comphelper::rng::seed( nSeed );
 }
 
 RTLFUNC(Rnd)
@@ -3544,9 +3545,7 @@ RTLFUNC(Rnd)
     }
     else
     {
-        double nRand = (double)rand();
-        nRand = ( nRand / ((double)RAND_MAX + 1.0));
-        rPar.Get(0)->PutDouble( nRand );
+        rPar.Get(0)->PutDouble( comphelper::rng::uniform() );
     }
 }
 


More information about the Libreoffice-commits mailing list