[1199] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 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. * |
---|
| 10 | // * * |
---|
| 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. * |
---|
| 17 | // * * |
---|
| 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 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // |
---|
| 27 | // $Id: G4ShootBitTest.cc,v 1.7 2006/06/29 19:00:58 gunter Exp $ |
---|
| 28 | // GEANT4 tag $Name: geant4-09-02-ref-02 $ |
---|
| 29 | // |
---|
| 30 | // |
---|
| 31 | |
---|
| 32 | // Tests RandFlat::fireBit() member function |
---|
| 33 | // Peter Urban, 5th Sep 1996 |
---|
| 34 | |
---|
| 35 | #include "G4ios.hh" |
---|
| 36 | #include <iomanip> |
---|
| 37 | #include "Randomize.hh" |
---|
| 38 | #include "G4Timer.hh" |
---|
| 39 | |
---|
| 40 | int main() |
---|
| 41 | { |
---|
| 42 | HepRandomEngine* e= HepRandom::getTheEngine(); |
---|
| 43 | RandFlat r(*e); |
---|
| 44 | |
---|
| 45 | const long NumTest= 10000; |
---|
| 46 | |
---|
| 47 | G4cout << "Printed value: (relative frequency - probability)" << G4endl; |
---|
| 48 | G4cout << NumTest << " random numbers" << G4endl << G4endl; |
---|
| 49 | |
---|
| 50 | long sum= 0; |
---|
| 51 | long i, j; |
---|
| 52 | |
---|
| 53 | for (i=0; i<NumTest; i++) { |
---|
| 54 | sum+= r.fireBit(); |
---|
| 55 | } |
---|
| 56 | G4cout << "fireBit " << double(sum)/NumTest-0.5 << G4endl; |
---|
| 57 | sum= 0; |
---|
| 58 | for (i=0; i<NumTest; i++) { |
---|
| 59 | sum+= r.shootBit(); |
---|
| 60 | } |
---|
| 61 | G4cout << "shootBit " << double(sum)/NumTest-0.5 << G4endl; |
---|
| 62 | sum= 0; |
---|
| 63 | for (i=0; i<NumTest; i++) { |
---|
| 64 | sum+= r.shootBit(e); |
---|
| 65 | } |
---|
| 66 | G4cout << "shootBit(engine) " << double(sum)/NumTest-0.5 << G4endl; |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | const long Num= 1000000; |
---|
| 70 | int iii; long lll; |
---|
| 71 | |
---|
| 72 | G4Timer theTimer; |
---|
| 73 | G4cout << G4endl << "Performance test: " << G4endl; |
---|
| 74 | |
---|
| 75 | G4cout << "shootBit() vs G4UniformRand()<0.5: "; |
---|
| 76 | theTimer.Start(); |
---|
| 77 | for (i=0; i<Num; i++) |
---|
| 78 | iii = RandFlat::shootBit(); |
---|
| 79 | theTimer.Stop(); |
---|
| 80 | G4cout << theTimer.GetUserElapsed() << " vs "; |
---|
| 81 | theTimer.Start(); |
---|
| 82 | for (i=0; i<Num; i++) |
---|
| 83 | G4UniformRand()<0.5; |
---|
| 84 | theTimer.Stop(); |
---|
| 85 | G4cout << theTimer.GetUserElapsed() << G4endl << G4endl; |
---|
| 86 | |
---|
| 87 | return 0; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | |
---|