//*CMZ : 2.00/00 21/01/98 08.36.06 by Rene Brun
//*CMZ : 1.03/09 05/12/97 13.19.06 by Fons Rademakers
//*-- Author : Rene Brun 15/12/95
//*KEEP,CopyRight,T=C.
/*************************************************************************
* Copyright(c) 1995-1998, The ROOT System, All rights reserved. *
* Authors: Rene Brun, Nenad Buncic, Valery Fine, Fons Rademakers. *
* *
* Permission to use, copy, modify and distribute this software and its *
* documentation for non-commercial purposes is hereby granted without *
* fee, provided that the above copyright notice appears in all copies *
* and that both the copyright notice and this permission notice appear *
* in the supporting documentation. The authors make no claims about the *
* suitability of this software for any purpose. *
* It is provided "as is" without express or implied warranty. *
*************************************************************************/
//*KEND.
//////////////////////////////////////////////////////////////////////////
// //
// TRandom //
// //
// Simple prototype random number generator class. //
// //
//////////////////////////////////////////////////////////////////////////
//*KEEP,TMath.
#include "TMath.h"
//*KEEP,TRandom,T=C++.
#include "TRandom.h"
//*KEND.
ClassImp(TRandom)
//______________________________________________________________________________
TRandom::TRandom(): TNamed("Random","Default Random number generator")
{
//*-*-*-*-*-*-*-*-*-*-*default constructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-* ===================
fSeed = 65539;
}
//______________________________________________________________________________
TRandom::~TRandom()
{
//*-*-*-*-*-*-*-*-*-*-*default destructor*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-* ==================
}
//______________________________________________________________________________
Float_t TRandom::Gaus(Float_t mean, Float_t sigma)
{
// Return a number distributed following a gaussian with mean and sigma
// Local variables
Float_t x, y, z, result;
y = Rndm();
if (!y) y = Rndm();
z = Rndm();
x = z * 6.283185;
result = mean + sigma*TMath::Sin(x)*TMath::Sqrt(-2*TMath::Log(y));
return result;
}
//______________________________________________________________________________
void TRandom::Rannor(Float_t &a, Float_t &b)
{
// Return 2 numbers distributed following a gaussian with mean=0 and sigma=1
// Local variables
Float_t r, x, y, z;
y = Rndm();
if (!y) y = Rndm();
z = Rndm();
x = z * 6.283185;
r = TMath::Sqrt(-2*TMath::Log(y));
a = r * TMath::Sin(x);
b = r * TMath::Cos(x);
}
//______________________________________________________________________________
Float_t TRandom::Rndm(Int_t)
{
// Machine independent random number generator.
// Produces uniformly-distributed floating points between 0 and 1.
// Identical sequence on all machines of >= 32 bits.
// Universal version (Fred james 1985).
const Float_t kCONS = 4.6566128730774E-10;
const Int_t kMASK31 = 2147483647;
fSeed *= 69069;
// keep only lower 31 bits
fSeed &= kMASK31;
// Set lower 8 bits to zero to assure exact float
Int_t jy = (fSeed/256)*256;
Float_t random = kCONS*jy;
return random;
}
ROOT page - Class index - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.