|
||||
File indexing completed on 2025-01-18 10:04:14
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 0026 //! Creates new Xorshift 64-bit RNG. 0027 math_BullardGenerator (unsigned int theSeed = 1) 0028 : myStateHi (theSeed) 0029 { 0030 SetSeed (theSeed); 0031 } 0032 0033 //! Setup new seed / reset defaults. 0034 void SetSeed (unsigned int theSeed = 1) 0035 { 0036 myStateHi = theSeed; 0037 myStateLo = theSeed ^ 0x49616E42; 0038 } 0039 0040 //! Generates new 64-bit integer value. 0041 unsigned int NextInt() 0042 { 0043 myStateHi = (myStateHi >> 2) + (myStateHi << 2); 0044 0045 myStateHi += myStateLo; 0046 myStateLo += myStateHi; 0047 0048 return myStateHi; 0049 } 0050 0051 //! Generates new floating-point value. 0052 Standard_Real NextReal() 0053 { 0054 return NextInt() / static_cast<Standard_Real> (0xFFFFFFFFu); 0055 } 0056 0057 private: 0058 0059 unsigned int myStateHi; 0060 unsigned int myStateLo; 0061 0062 }; 0063 0064 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |