2 // ********************************************************************
 
    3 // * License and Disclaimer                                           *
 
    5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
 
    6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
 
    7 // * conditions of the Geant4 Software License,  included in the file *
 
    8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
 
    9 // * include a list of copyright holders.                             *
 
   11 // * Neither the authors of this software system, nor their employing *
 
   12 // * institutes,nor the agencies providing financial support for this *
 
   13 // * work  make  any representation or  warranty, express or implied, *
 
   14 // * regarding  this  software system or assume any liability for its *
 
   15 // * use.  Please see the license in the file  LICENSE  and URL above *
 
   16 // * for the full disclaimer and the limitation of liability.         *
 
   18 // * This  code  implementation is the result of  the  scientific and *
 
   19 // * technical work of the GEANT4 collaboration.                      *
 
   20 // * By using,  copying,  modifying or  distributing the software (or *
 
   21 // * any work based  on the software)  you  agree  to acknowledge its *
 
   22 // * use  in  resulting  scientific  publications,  and indicate your *
 
   23 // * acceptance of all terms of the Geant4 Software license.          *
 
   24 // ********************************************************************
 
   30 G4MTRandFlat(CLHEP::HepRandomEngine & anEngine)
 
   31 : firstUnusedBit(0), localEngine(&anEngine), deleteEngine(false), 
 
   32   defaultA(0.0), defaultB(1.0) {}
 
   35 G4MTRandFlat(CLHEP::HepRandomEngine & anEngine, G4double width )
 
   36 : firstUnusedBit(0), localEngine(&anEngine), deleteEngine(false), 
 
   37   defaultA(0.0), defaultB(width) {}
 
   40 G4MTRandFlat(CLHEP::HepRandomEngine & anEngine, G4double a, G4double b )
 
   41 : firstUnusedBit(0), localEngine(&anEngine), deleteEngine(false), 
 
   42   defaultA(a), defaultB(b) {}
 
   45 G4MTRandFlat(CLHEP::HepRandomEngine * anEngine)
 
   46 : firstUnusedBit(0), localEngine(anEngine), deleteEngine(true), 
 
   47   defaultA(0.0), defaultB(1.0) {}
 
   50 G4MTRandFlat(CLHEP::HepRandomEngine * anEngine, G4double width )
 
   51 : firstUnusedBit(0), localEngine(anEngine), deleteEngine(true), 
 
   52   defaultA(0.0), defaultB(width) {}
 
   55 G4MTRandFlat(CLHEP::HepRandomEngine * anEngine, G4double a, G4double b )
 
   56 : firstUnusedBit(0), localEngine(anEngine), deleteEngine(true), 
 
   57   defaultA(a), defaultB(b) {}
 
   59 inline G4double G4MTRandFlat::shoot(G4double a, G4double b)
 
   61   return (b-a)* shoot() + a;
 
   64 inline G4double G4MTRandFlat::shoot(G4double width)
 
   66   return width * shoot();
 
   69 inline G4long G4MTRandFlat::shootInt(G4long n)
 
   71   return G4long(shoot()*G4double(n));
 
   74 inline G4long G4MTRandFlat::shootInt(G4long mLong, G4long nLong)
 
   76   return G4long(shoot()*G4double(nLong-mLong)) + mLong;
 
   79 inline void G4MTRandFlat::shootBits()
 
   81   const G4double factor= 2.0*MSB; // this should fit into a double! 
 
   82   staticFirstUnusedBit= MSB;
 
   83   staticRandomInt= (unsigned long)(factor*shoot());  
 
   86 inline G4int G4MTRandFlat::shootBit()
 
   88   if (staticFirstUnusedBit==0)
 
   90   unsigned long temp= staticFirstUnusedBit&staticRandomInt;
 
   91   staticFirstUnusedBit>>= 1;
 
   95 //---------------------
 
   97 inline G4double G4MTRandFlat::shoot(CLHEP::HepRandomEngine* anEngine)
 
   99   return anEngine->flat();
 
  103 inline G4double G4MTRandFlat::shoot(CLHEP::HepRandomEngine* anEngine,
 
  104                                     G4double a, G4double b)
 
  106   return (b-a)* anEngine->flat() + a;
 
  109 inline G4double G4MTRandFlat::shoot(CLHEP::HepRandomEngine* anEngine,
 
  112   return width * anEngine->flat();
 
  115 inline G4long G4MTRandFlat::shootInt(CLHEP::HepRandomEngine* anEngine,
 
  118   return G4long(anEngine->flat()*G4double(n));
 
  121 inline G4long G4MTRandFlat::shootInt(CLHEP::HepRandomEngine* anEngine,
 
  122                                      G4long mparam, G4long n)
 
  124   return G4long(G4double(n-mparam)*anEngine->flat()) + mparam;
 
  127 inline void G4MTRandFlat::shootArray(CLHEP::HepRandomEngine* anEngine,
 
  128                                      const G4int size, G4double* vect)
 
  130   anEngine->flatArray(size,vect);
 
  133 inline void G4MTRandFlat::shootBits(CLHEP::HepRandomEngine* engine)
 
  135   const G4double factor= 2.0*MSB; // this should fit into a double! 
 
  136   staticFirstUnusedBit= MSB;
 
  137   staticRandomInt= (unsigned long)(factor*shoot(engine));  
 
  140 inline G4int G4MTRandFlat::shootBit(CLHEP::HepRandomEngine* engine)
 
  142   if (staticFirstUnusedBit==0)
 
  144   unsigned long temp= staticFirstUnusedBit&staticRandomInt;
 
  145   staticFirstUnusedBit>>= 1;
 
  149 //---------------------
 
  151 inline G4double G4MTRandFlat::fire()
 
  153   return (defaultB-defaultA)*localEngine->flat()+defaultA;
 
  156 inline G4double G4MTRandFlat::fire(G4double a, G4double b)
 
  158   return (b-a)* localEngine->flat() + a;
 
  161 inline G4double G4MTRandFlat::fire(G4double width)
 
  163   return width * localEngine->flat();
 
  166 inline G4long G4MTRandFlat::fireInt(G4long n)
 
  168   return G4long(localEngine->flat()*G4double(n));
 
  171 inline G4long G4MTRandFlat::fireInt(G4long mparam, G4long n)
 
  173   return G4long(localEngine->flat()*G4double(n-mparam)) + mparam;
 
  176 inline void G4MTRandFlat::fireBits()
 
  178   const G4double factor= 2.0*MSB; // this should fit into a double! 
 
  180   randomInt= (unsigned long)(factor*localEngine->flat());  
 
  183 inline G4int G4MTRandFlat::fireBit()
 
  185   if (firstUnusedBit==0)
 
  187   unsigned long temp= firstUnusedBit&randomInt;