Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-26 09:17:02

0001 // Created on: 2014-07-18
0002 // Created by: Alexander Malyshev
0003 // Copyright (c) 2014-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _math_BullardGenerator_HeaderFile
0017 #define _math_BullardGenerator_HeaderFile
0018 
0019 #include <Standard_Real.hxx>
0020 
0021 //! Fast random number generator (the algorithm proposed by Ian C. Bullard).
0022 class math_BullardGenerator
0023 {
0024 public:
0025   //! Creates new Xorshift 64-bit RNG.
0026   math_BullardGenerator(unsigned int theSeed = 1)
0027       : myStateHi(theSeed)
0028   {
0029     SetSeed(theSeed);
0030   }
0031 
0032   //! Setup new seed / reset defaults.
0033   void SetSeed(unsigned int theSeed = 1)
0034   {
0035     myStateHi = theSeed;
0036     myStateLo = theSeed ^ 0x49616E42;
0037   }
0038 
0039   //! Generates new 64-bit integer value.
0040   unsigned int NextInt()
0041   {
0042     myStateHi = (myStateHi >> 2) + (myStateHi << 2);
0043 
0044     myStateHi += myStateLo;
0045     myStateLo += myStateHi;
0046 
0047     return myStateHi;
0048   }
0049 
0050   //! Generates new floating-point value.
0051   Standard_Real NextReal() { return NextInt() / static_cast<Standard_Real>(0xFFFFFFFFu); }
0052 
0053 private:
0054   unsigned int myStateHi;
0055   unsigned int myStateLo;
0056 };
0057 
0058 #endif