1 // Created on: 2014-07-18
2 // Created by: Alexander Malyshev
3 // Copyright (c) 2014-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _math_BullardGenerator_HeaderFile
17 #define _math_BullardGenerator_HeaderFile
19 #include <Standard_Real.hxx>
21 //! Fast random number generator (the algorithm proposed by Ian C. Bullard).
22 class math_BullardGenerator
26 //! Creates new Xorshift 64-bit RNG.
27 math_BullardGenerator (unsigned int theSeed = 1)
33 //! Setup new seed / reset defaults.
34 void SetSeed (unsigned int theSeed = 1)
37 myStateLo = theSeed ^ 0x49616E42;
40 //! Generates new 64-bit integer value.
41 unsigned int NextInt()
43 myStateHi = (myStateHi >> 2) + (myStateHi << 2);
45 myStateHi += myStateLo;
46 myStateLo += myStateHi;
51 //! Generates new floating-point value.
52 Standard_Real NextReal()
54 return NextInt() / static_cast<Standard_Real> (0xFFFFFFFFu);
59 unsigned int myStateHi;
60 unsigned int myStateLo;