// shows the correlations of the infamous RANDU random generator
//
//         jtmn, Ago, 2003

 Int_t gRandu(Int_t &iseed){
  Int_t prod=65539*iseed;
  Int_t m = TMath::Power(2,31);
  iseed = prod%m;
  return iseed/TMath::Power(2.0,31);
    }

void randu()
{

 gROOT->Reset();
 gROOT->SetStyle("Plain"); 

 const Int_t nPoints = 20000;

 Float_t  x[nPoints];
 Float_t  y[nPoints];
 Float_t  z[nPoints];

 //generate x, y dist
 Int_t iseed = 300;
 for (Int_t i=0;i<nPoints;i++) {
   x[i] = gRandu(iseed);
   y[i] = gRandu(iseed);
  }

 // display bidim dist 
 TCanvas *c1 = new TCanvas("c1"," Points ", 600,600);
 plane  = new TH2F("plane"," ", 50,-1.0,1.0,50,-1.0,1.0);
 for (Int_t i=0;i<nPoints;i++){
   plane->Fill(x[i],y[i]);
  }
 plane->SetStats(kFALSE);
 plane->GetXaxis()->SetTitle("x_{uncorr}");
 plane->GetYaxis()->SetTitle("y_{uncorr}");
 plane.Draw();
 Double_t r = plane->GetCorrelationFactor();
 cout << " r = " << r << endl;
 c1->Update();


 Int_t iseed = 300;
 // generate x, y, z distrib
 for (Int_t i=0;i<nPoints;i++) {
   x[i] = gRandu(iseed);
   y[i] = gRandu(iseed);
   z[i] = gRandu(iseed);
  }

 // display tridim dist
 TCanvas *c2 = new TCanvas("c2"," Points ", 600,600);
 cube  = new TH3F("cube"," ", 50,-1.0,1.0,50,-1.0,1.0, 50, -1.0,1.0);
 for (Int_t i=0;i<nPoints;i++){
   cube->Fill(x[i],y[i],z[i]);
  }
 cube.Draw();
 c2->Update();

}
