0025717: Non reentrant (and hence non-thread-safe) math_RealRandom / _IntegerRandom
authorabv <abv@opencascade.com>
Sun, 18 Jan 2015 14:08:40 +0000 (17:08 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 29 Jan 2015 11:09:42 +0000 (14:09 +0300)
Classes math_IntegerRandom and math_RealRandom, and method Random2 in math_Recipes, removed. Class math_BullardGenerator is used instead.

src/BRepClass3d/BRepClass3d_SClassifier.cxx
src/math/math.cdl
src/math/math_IntegerRandom.cdl [deleted file]
src/math/math_IntegerRandom.cxx [deleted file]
src/math/math_RealRandom.cdl [deleted file]
src/math/math_RealRandom.cxx [deleted file]
src/math/math_Recipes.cxx
src/math/math_Recipes.hxx

index a53020f..4d01b20 100644 (file)
@@ -30,7 +30,7 @@
 #include <ElCLib.hxx>
 #include <Geom_Surface.hxx>
 #include <BRep_Tool.hxx>
-#include <math_RealRandom.hxx>
+#include <math_BullardGenerator.hxx>
 #include <BRepTopAdaptor_FClass2d.hxx>
 
 static
@@ -98,7 +98,7 @@ void BRepClass3d_SClassifier::PerformInfinitePoint(BRepClass3d_SolidExplorer& aS
   gp_Pnt aPoint;
   gp_Dir aDN;
 
-  math_RealRandom RandomGenerator(0.1, 0.9);
+  math_BullardGenerator aRandomGenerator;
   myFace.Nullify();
   myState=2;
 
@@ -114,10 +114,10 @@ void BRepClass3d_SClassifier::PerformInfinitePoint(BRepClass3d_SolidExplorer& aS
       TopoDS_Face MinFace = aF;
       for (;;)
       {
-        aParam = RandomGenerator.Next();
-       bFound = aSE.FindAPointInTheFace(aF, aPoint, aU, aV, aParam);
-       if (!bFound)
-         return;
+        aParam = 0.1 + 0.8 * aRandomGenerator.NextReal(); // random number in range [0.1, 0.9]
+        bFound = aSE.FindAPointInTheFace(aF, aPoint, aU, aV, aParam);
+        if (!bFound)
+          return;
 
         if (!FaceNormal(aF, aU, aV, aDN))
           continue;
index 7fe5438..1808125 100644 (file)
@@ -55,7 +55,6 @@ is
     imported PSO;
     imported PSOParticlesPool;
     imported BullardGenerator;
-    class IntegerRandom;
     class Gauss;
     class GaussLeastSquare;
     class SVD;
@@ -77,7 +76,6 @@ is
     class GaussSingleIntegration;
     class GaussMultipleIntegration;
     class GaussSetIntegration;
-    class RealRandom;
     class FunctionSample;
     class FunctionAllRoots;    
     class Householder;
diff --git a/src/math/math_IntegerRandom.cdl b/src/math/math_IntegerRandom.cdl
deleted file mode 100644 (file)
index 419f856..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
--- Created on: 1991-05-27
--- Created by: Laurent PAINNOT
--- Copyright (c) 1991-1999 Matra Datavision
--- Copyright (c) 1999-2014 OPEN CASCADE SAS
---
--- This file is part of Open CASCADE Technology software library.
---
--- This library is free software; you can redistribute it and/or modify it under
--- the terms of the GNU Lesser General Public License version 2.1 as published
--- by the Free Software Foundation, with special exception defined in the file
--- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
--- distribution for complete text of the license and disclaimer of any warranty.
---
--- Alternatively, this file may be used under the terms of Open CASCADE
--- commercial license or contractual agreement.
-
-class IntegerRandom from math
-   ---Purpose:
-   -- This class implements an integer random number generator.
-
-is
-
-   Create(Lower, Upper: Integer)
-   ---Purpose:
-   -- creates a Integer random generator between the values Lower and Upper.
-    
-   returns IntegerRandom;
-   
-    
-   Reset(me:in out)
-       ---Purpose: reinitializes the random generator
-
-   is static;
-
-   Next(me: in out)
-    ---Purpose: returns the next random number.
-
-   returns Integer
-   is static;
-   
-fields
-
-Low:    Integer;
-Up:     Integer;
-Dummy:  Integer;
-
-end IntegerRandom;
diff --git a/src/math/math_IntegerRandom.cxx b/src/math/math_IntegerRandom.cxx
deleted file mode 100644 (file)
index 4c00cd4..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright (c) 1997-1999 Matra Datavision
-// Copyright (c) 1999-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <math_IntegerRandom.ixx>
-
-#include <math_Recipes.hxx>
-
-math_IntegerRandom::math_IntegerRandom(const Standard_Integer Lower, 
-                                        const Standard_Integer Upper) {
-
-   Low = Lower;
-   Up = Upper;
-   Dummy=-1;
-   Random2(Dummy);
- }
-
-void math_IntegerRandom::Reset() {
-  Dummy=-1;
-  Random2(Dummy);
-}
-
-Standard_Integer math_IntegerRandom::Next() {
-
-  Standard_Real value=Random2(Dummy);
-  Standard_Integer Result=(Standard_Integer)(Standard_Real((Up-Low))*value + Low);
-  return (Result) ;
-}
-
diff --git a/src/math/math_RealRandom.cdl b/src/math/math_RealRandom.cdl
deleted file mode 100644 (file)
index b83410b..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
--- Created on: 1991-05-14
--- Created by: Laurent PAINNOT
--- Copyright (c) 1991-1999 Matra Datavision
--- Copyright (c) 1999-2014 OPEN CASCADE SAS
---
--- This file is part of Open CASCADE Technology software library.
---
--- This library is free software; you can redistribute it and/or modify it under
--- the terms of the GNU Lesser General Public License version 2.1 as published
--- by the Free Software Foundation, with special exception defined in the file
--- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
--- distribution for complete text of the license and disclaimer of any warranty.
---
--- Alternatively, this file may be used under the terms of Open CASCADE
--- commercial license or contractual agreement.
-
-class RealRandom from math
-    ---Purpose:
-    -- This class implements a real random generator.
-
-
-is
-
-   Create(Lower, Upper: Real)
-    ---Purpose:
-    -- creates a real random generator between the values Lower and Upper.
-
-   returns RealRandom;
-   
-
-   Reset(me: in out)
-    ---Purpose: reinitializes the random generator
-
-   is static;
-   
-   Next(me: in out)
-    ---Purpose: returns the next random number.
-
-   returns Real
-   is static;
-
-
-fields
-
-Dummy:  Integer;
-Low:    Real;
-Up:     Real;
-
-end RealRandom;
diff --git a/src/math/math_RealRandom.cxx b/src/math/math_RealRandom.cxx
deleted file mode 100644 (file)
index 1c6c2f6..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (c) 1997-1999 Matra Datavision
-// Copyright (c) 1999-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <math_RealRandom.ixx>
-#include <math_Recipes.hxx>
-
-math_RealRandom::math_RealRandom(const Standard_Real Lower,
-                                const Standard_Real Upper) {
-
-  Low = Lower;
-  Up = Upper;
-  Dummy = -1;
-  Random2(Dummy);
-}
-
-void math_RealRandom::Reset() {
-
-  Dummy = -1;
-  Random2(Dummy);
-}
-
-Standard_Real math_RealRandom::Next() {
-  
-  Standard_Real value = Random2(Dummy);
-  Standard_Real Result = (Up - Low)*value + Low;
-  return Result;  
-
-}
index 97794a1..cdd7e23 100644 (file)
@@ -562,33 +562,6 @@ void SVD_Solve(const math_Matrix& u,
      }
 }  
 
-Standard_Real Random2(Standard_Integer& idum) {
-
-  static Standard_Integer iy, ir[98];
-  static Standard_Integer iff = 0;
-  Standard_Integer j;
-
-  if(idum < 0 || iff == 0) {
-    iff = 1;
-    if((idum = (IC - idum) % M) < 0) idum = -idum;
-    for(j = 1; j <= 97; j++) {
-      idum = (IA * idum + IC) % M;
-      ir[j] = idum;
-    }
-    idum = (IA * idum + IC) % M;
-    iy = idum;
-  }
-  j = (Standard_Integer)(1 + 97.0 * iy / M);
-  if(j > 97 || j < 1) Standard_Failure::Raise();
-  iy = ir[j];
-  idum = (IA * idum + IC) % M;
-  ir[j] = idum;
-  return Standard_Real(iy) / Standard_Real(M);
-}
-
-
-
 Standard_Integer DACTCL_Decompose(math_Vector& a, 
                        const math_IntegerVector& indx,
                         const Standard_Real MinPivot) {
index adcfb2b..5a06863 100644 (file)
@@ -151,13 +151,6 @@ __math_API Standard_Integer Jacobi(math_Matrix& a, math_Vector& d, math_Matrix&
 // Eigenvalues are sorted into descending order, and eigenvectors are 
 // arranges correspondingly.
 
-__math_API Standard_Real Random2(Standard_Integer& idum);
-
-// returns a uniform random deviate betwween 0.0 and 1.0. Set idum to any
-// negative value to initialize or reinitialize the sequence.
-
-
-
 #endif