#include "getpidip.h" #include "cfortran.h" #include "TSystem.h" #include "TString.h" #include "TInetAddress.h" #include "TRandom3.h" #include "TDatime.h" #include #include using namespace std; void getpidip(Int_t* pid, Int_t* ip, Int_t* r1, Int_t* r2) { TString hostname = gSystem->HostName(); TInetAddress address = gSystem->GetHostByName(hostname.Data()); *pid = gSystem->GetPid(); *ip = 0; TString sip = address.GetHostAddress(); if(sip.Contains(".") && sip.Last('.')!=0){ sip.Replace(0.,sip.Last('.')+1,""); *ip = sip.Atoi(); } TDatime datime; UInt_t t = datime.Get(); TRandom3 generator(t+*pid*1000+*ip*1000); UInt_t rndNum = 0; *r1 = generator.Rndm()*(kMaxInt-1); *r2 = generator.Rndm()*(kMaxInt-1); // Open as read only random device for strong randomization Int_t fp = open("/dev/urandom", O_RDONLY); if(fp < 0){ cout<<" getpidip() : Could not open /dev/urandom for reading : will take numbers from TRandom3"<kMaxInt){ // make sure they are in rang of int ret = read(fp, &rndNum, sizeof(rndNum)); } *r1 = rndNum; read(fp, &rndNum, sizeof(rndNum)); while(rndNum>kMaxInt){ ret = read(fp, &rndNum, sizeof(rndNum)); } *r2 = rndNum; close(fp); } } cout<<" getpidip() : "<