/* Performance Measurements */ ptr_t PM_1_INSERTION(data_t *myHeap, data_t *Master2SysAlloc, int *fixedStack, int stackPtr_avl, int log2_tree_size){ ptr_t root = NULL_PTR; if(TestCase == USE_RANDOM_KEYS){ int log2_RNG_num_range = log2_tree_size - 1; // generate half the range from RNG int IterationRange = 1 << log2_RNG_num_range; int i; for(i = 0; i < IterationRange; i++){ int key = RandGen(log2_RNG_num_range); struct ptrBundle_t temp = Insert(myHeap, Master2SysAlloc, fixedStack, stackPtr_avl, root, key); root = temp.root; } }else{ int m = log2_tree_size - 1; int iter = 1 << m; int i; for(i = 0; i < iter; i++){ int key = 16*(i+1); struct ptrBundle_t temp = Insert(myHeap, Master2SysAlloc, fixedStack, stackPtr_avl, root, key); root = temp.root; } } root = root +1; return root; }
ptr_t PM_2_CHECK_INSERTION(data_t *myHeap, data_t *Master2SysAlloc, int *fixedStack, int stackPtr_avl, ptr_t root, int log2_tree_size){ if(TestCase == USE_SEQUENTIAL_KEYS){ int m = log2_tree_size - 1; int iter = 1 << m; int i; for(i = 0; i < iter; i++){ int key = RandGen(log2_tree_size+2); root = Check_thenInsert(myHeap, Master2SysAlloc, fixedStack, stackPtr_avl, root, key); } }else{ int log2_RNG_num_range = log2_tree_size; // generate FULL range from RNG int IterationRange = 1 << (log2_RNG_num_range - 1); // only get half of them int i; for(i = 0; i < IterationRange; i++){ int key = RandGen(log2_RNG_num_range); root = Check_thenInsert(myHeap, Master2SysAlloc, fixedStack, stackPtr_avl, root, key); } } return root+1; }
ptr_t PM_3_UPDATE(data_t *myHeap, data_t *Master2SysAlloc, int *fixedStack, int *secondStack, int stackPtr_avl, ptr_t root, int log2_tree_size){ if(TestCase == USE_SEQUENTIAL_KEYS){ int m = log2_tree_size - 1; int iter = 1 << m; int i; for(i = 0; i < iter; i++){ int oldKey = RandGen(log2_tree_size+2); int newKey = RandGen(log2_tree_size+3); root = UpdateNode(myHeap, Master2SysAlloc, fixedStack, secondStack, stackPtr_avl, root, oldKey, newKey); } }else{ int IterationRange = 1 << (log2_tree_size - 1); int i; for(i = 0; i < IterationRange; i++){ int oldKey = RandGen(log2_tree_size - 1); int newKey = RandGen(log2_tree_size); root = UpdateNode(myHeap, Master2SysAlloc, fixedStack, secondStack, stackPtr_avl, root, oldKey, newKey); } } return root+1; }
void PM3_RANDOM_ACCESS(int *hdVector, int log2size){ int iter = 1 << (log2size-1); //printf("PM3: "); int i; for(i = 0; i < iter; i++){ int index = RandGen(log2size) - 2; if(index < 0){ index = 0; } int temp = vector_read_data(hdVector, index); //printf("%d, ",temp); } //printf("\n"); }
std::string CLogin::GenCode(std::string User) { std::string Code; // Create auth code for user for (int i = 0; i < 30; i++) { int Character=1; do Character = RandGen() % (126 - 33) + 33; while ((char)Character == '"' || (char)Character == '\\'); Code += (char) Character; } // Add user entry to list LoginData NewLogin; NewLogin.AuthCode = Code; NewLogin.is_auth = false; NewLogin.User = User; Users.push_back(NewLogin); return Code; }
void PositionPowerUps(int *powerUpOrder) { static long initSeed = -IM; float randFloat; int randNum; bool zeroSelected = false, oneSelected = false, twoSelected = false, threeSelected = false, fourSelected = false; static bool indexStored; // If value is going to be stored. int i = 0; // Position index. while(!zeroSelected || !oneSelected || !twoSelected || !threeSelected || !fourSelected) { randFloat = RandGen(&initSeed); randNum = (int)(1e6 * randFloat) % 5; switch(randNum) { case 0: if(!zeroSelected) { powerUpOrder[i] = randNum; indexStored = true; } else indexStored = false; // Not stored, so go through iteration again. zeroSelected = true; // We know that this value has been selected and either stored or not. break; case 1: if(!oneSelected) { powerUpOrder[i] = randNum; indexStored = true; } else indexStored = false; oneSelected = true; break; case 2: if(!twoSelected) { powerUpOrder[i] = randNum; indexStored = true; } else indexStored = false; twoSelected = true; break; case 3: if(!threeSelected) { powerUpOrder[i] = randNum; indexStored = true; } else indexStored = false; threeSelected = true; break; case 4: if(!fourSelected) { powerUpOrder[i] = randNum; indexStored = true; } else indexStored = false; fourSelected = true; break; } if(indexStored) i++; // Increment the index if successful. else indexStored = true; // If unsuccessful storage, let index remain at current value and set indexStored to receive next value. } }
#include "stdafx.h" #include "Rand.h" UINT MyRand::m_uKey = 0 ; CHAR MyRand::m_pKey[MAX_KEY_SIZE] ; MyLock MyRand::m_Lock ; RandGen g_RandGen = RandGen((unsigned)time(NULL)); MyRand::MyRand( ) { } MyRand::~MyRand( ) { } VOID MyRand::SetRand( UINT uKey ) { m_Lock.Lock() ; m_uKey = uKey%MAX_KEY_SIZE ; m_Lock.Unlock() ; } UINT MyRand::Rand( ) { m_Lock.Lock() ;
void Random::seed(unsigned int i) { mGen = RandGen(i); }
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------ void Calculate_Baseline( std::vector<double> DIAM,std::vector<double> ARC, std::vector<double> &baseline, std::vector<double> &weights ){ baseline.clear(); weights.clear(); unsigned int Npoints = ARC.size(); baseline.resize(Npoints, 0.0); weights.resize(Npoints, 0.0); std::vector<double> r_mad (Npoints, 0.0); std::vector<double> DIAM_noise (Npoints, 0.0); double MIN_, MAX_; //REMOVE OUTLIERS USING MAD (Median Absolute Deviation) double outlier_cutoff = 3.0; double median_D, mad; median_D = MEDIAN(DIAM); for(unsigned i = 0; i < Npoints; i = i + 1) { r_mad[i] = abs( DIAM[i] - median_D ); } mad = MEDIAN(r_mad); // use fitting weights to exclude the outliers if( mad > 1.0e-6 ) { for(unsigned i = 0; i < Npoints; i = i + 1 ) { r_mad[i] = abs( DIAM[i] - median_D ) / mad; if( r_mad[i] > outlier_cutoff ) { weights[i] = 0.0; } else { weights[i] = 1.0; } } } else { // will end up here if more than 50% of data points had the same value // add 1% noise to DIAM profile and recalculate mad std::vector<double> DIAM_noise = DIAM; MIN_ = MINIMUM(DIAM); for (unsigned i=0; i < Npoints; i = i + 1 ) { DIAM_noise[i] = DIAM[i] * 0.01 * MIN_ * RandGen((double)-1.0,(double)1.0); } median_D = MEDIAN(DIAM_noise); for(unsigned i = 0; i < Npoints; i = i + 1) { r_mad[i] = abs( DIAM_noise[i] - median_D ); } mad = MEDIAN(r_mad); if( mad > 1.0e-6 ) { for(unsigned i = 0; i < Npoints; i = i + 1 ) { r_mad[i] = abs( DIAM_noise[i] - median_D ) / mad; if( r_mad[i] > outlier_cutoff ) { weights[i] = 0.0; } else { weights[i] = 1.0; } } }else{ //this is tricky situation; try signalling outliers assuming Normal dist... double s = STDEV(DIAM); median_D = MEDIAN(DIAM); for(unsigned i = 0; i < Npoints; i = i + 1 ) { if( abs( DIAM[i] - median_D ) > 2.0 * s ) { weights[i] = 0.0; } else { weights[i] = 1.0; } } } } //PERFORM 2ND ORDER POLYNOMIAL FIT double a, b, c; std::vector<double> temp_mad; double w1 = 0.0; double wx = 0.0, wx2 = 0.0, wx3 = 0.0, wx4 = 0.0; double wy = 0.0, wyx = 0.0, wyx2 = 0.0; double tmpx = 0.0, tmpy = 0.0; double den; double x, y, w; if(DIAM.size()-SUM(weights)>2){ for(unsigned i = 0; i < Npoints; i = i + 1 ) { x = ARC[i]; y = DIAM[i]; w = weights[i]; w1 += w; tmpx = w * x; wx += tmpx; tmpx *= x; wx2 += tmpx; tmpx *= x; wx3 += tmpx; tmpx *= x; wx4 += tmpx; tmpy = w * y; wy += tmpy; tmpy *= x; wyx += tmpy; tmpy *= x; wyx2 += tmpy; } den = wx2 * wx2 * wx2 - 2.0 * wx3 * wx2 * wx + wx4 * wx * wx + wx3 * wx3 * w1 - wx4 * wx2 * w1; if( den == 0.0 ) { a = 0.0; b = 0.0; c = 0.0; } else { a = (wx * wx * wyx2 - wx2 * w1 * wyx2 - wx2 * wx * wyx + wx3 * w1 * wyx + wx2 * wx2 * wy - wx3 * wx * wy) / den; b = (-wx2 * wx * wyx2 + wx3 * w1 * wyx2 + wx2 * wx2 * wyx - wx4 * w1 * wyx - wx3 * wx2 * wy + wx4 * wx * wy) / den; c = (wx2 * wx2 * wyx2 - wx3 * wx * wyx2 - wx3 * wx2 * wyx + wx4 * wx * wyx + wx3 * wx3 * wy - wx4 * wx2 * wy) / den; } // FILL IN DATA double d; for(unsigned i = 0; i < Npoints; i = i + 1 ) { x = ARC[i]; d = a * x * x + b * x + c; if( d > 1.0e-6 ) { baseline[i] = d; } else { baseline[i] = 1.0e-6; } } }else{ median_D = MEDIAN(DIAM); for(unsigned i = 0; i < Npoints; i = i + 1 ) { baseline[i] = median_D; } } // Do not allow the baseline to go bellow the minimal diameter, or above maximal diameter - truncate MIN_ = MINIMUM(DIAM); MAX_ = MAXIMUM(DIAM); for(unsigned i = 0; i < Npoints; i = i + 1 ) { if (baseline[i]<MIN_){ baseline[i] = MIN_; } if (baseline[i]>MAX_){ baseline[i] = MAX_; } } return; }
/*main function*/ int main() { int a = 0, b = 0, c = 0; char input[length], color[length], correct = 'F', Q = 'T'; char player[50]; char victory,ans; int x = 0; do{ print_score(); num++; if(x>0)/*only after one trial, then ask.*/ { ans = ask(); if(ans == 'N') { return 0; } else if( ans == 'Y') { printf("\tEnjoy the game. :)\n\n"); system ("pause"); system ("cls"); } else { return 0; } } x=0; welcome(); Info(); printf("\n\n"); RandGen(color); printf("\n"); options(); do { options1(x); for( a=0; a<length; a++) { ans = scan(input,a, color); if(ans == 'Q') { return 0; } else if(ans == 'I') { x--; break; } } x++; victory = check1(input, color); check2(input, color); if(victory == 'T') { part[num].score = x; congrat(); break; } c++; if(c == 20) { part[num].score = 9999; break; } }while(c < 21); }while(b = 1); }