#include #include #include ////////////////////////////////////////////////////////////////////// //This file is part of a chain of processes.. it is not meant to be //run directly.. the script 'runme' has to make a file 'grepfile' for //this program to look at and generate a number from.. //When this program is done running, there will be a file 'random.byte' //in this directory.. The java class 'sendrn' will read the integer //out of 'random.byte' and send it to the random number server.. ////////////////////////////////////////////////////////////////////// main () { ifstream fin("grepfile"); //open filestream, error if not if ( !fin ) { cout << "run the script file, this program is not meant to be " << "executed directly.. Run the script 'runme'" << endl; exit(1); } int rn=0; //some variables.. char tmp[60]; int pid; for ( int i=0 ; i<8 ; i++ ) { //for each bit (line fin >> pid; //in grepfile) fin.getline(tmp,60,'\n'); if ( !fin ) { cout << "corrupt grepfile.." << endl; exit(1); } if ( pid%2 == 0 ) { //if pid is even, do nothing } else { //if odd, record a '1' for rn=rn+(int)pow(2,i); //that bit, update RN } } ofstream fout("random.byte"); if ( !fout ) { cerr << "error opening outfilestream : random.byte" << endl; exit(1); } fout << (char)rn; //write the random number cout << rn << " "; return 0; //into a file for the next } //prg in the chain to process