unsigned int well_init_time(well *rng) { unsigned int seed = time_seed(); while (seed == 0) { seed = time_seed(); }; well_init(rng, seed); return seed; }
/* Set the program parameters from the command-line arguments */ void parameters(int argc, char **argv) { int seed = 0; /* Random seed */ char uid[32]; /*User name */ /* Read command-line arguments */ srand(time_seed()); /* Randomize */ if (argc == 3) { seed = atoi(argv[2]); srand(seed); printf("Random seed = %i\n", seed); } if (argc >= 2) { N = atoi(argv[1]); if (N < 1 || N > MAXN) { printf("N = %i is out of range.\n", N); exit(0); } } else { printf("Usage: %s <matrix_dimension> [random seed]\n", argv[0]); exit(0); } /* Print parameters */ printf("\nMatrix dimension N = %i.\n", N); }
int main( ){ srand( time_seed() ); individual* i; i = create_individual(); print_individual( i, 0 ); evaluate_individual( i ); print_individual( i, 0 ); }
void sfmt_init_stable_r(sfmt_t *sfmt){ uint32_t init_array[SFMT_N32]; struct timeval tp; union lcg_state lcg_init; lcg_init.X_i=time_seed(); int i; for(i=0;i<SFMT_N32;i++){ init_array[i]=nrand48(lcg_init.state); } sfmt_init_by_array(sfmt,init_array,SFMT_N32); }
void set_random(void * ptr, int len) { int x; unsigned char * punned_ptr; /* ptr for type punning header->salt */ /* Seed the rng */ srand(time_seed()); punned_ptr = (unsigned char *)ptr; for(x = 0; x < len; ++x) punned_ptr[x] = rand() % (UCHAR_MAX + 1); }
void SimAnneal::Initialize(ReflSettings* InitStruct) { m_bdebugging = InitStruct->Debug; m_iPlattime = InitStruct->Platiter; m_dAveragefSTUN = InitStruct->Inittemp; if(m_dTemp == -1) { if(!InitStruct->Adaptive) { m_dTemp = 1.0/InitStruct->Inittemp; } else { m_dTemp = 10; } } //SA Parameters m_iIteration = 0; m_iTime = 0; m_dgamma = InitStruct->Gamma; m_dslope = InitStruct->Slope; m_itempiter = InitStruct->Tempiter; m_badaptive = InitStruct->Adaptive; m_iSTUNfunc = InitStruct->STUNfunc; m_iSTUNdec = InitStruct->STUNdeciter; m_dgammadec = InitStruct->Gammadec; //Pertubation parameters mc_stepsize = InitStruct->Paramtemp; m_isigmasearch = InitStruct->Sigmasearch; m_inormsearch = InitStruct->NormalizationSearchPerc; m_iabssearch = InitStruct->AbsorptionSearchPerc; m_ialgorithm = InitStruct->Algorithm; if(m_bdebugging) { debugfile.open(wstring(InitStruct->Directory + wstring(L"\\debug.txt")).c_str()); rejfile.open(wstring(InitStruct->Directory + wstring(L"\\rejfile.txt")).c_str()); } //Initialize the random number generator srand(time_seed()); }
/* Set the program parameters from the command-line arguments */ void parameters(int argc, char **argv) { int submit = 0; /* = 1 if submission parameters should be used */ int seed = 0; /* Random seed */ char uid[L_cuserid + 2]; /*User name */ seed = time_seed(); procs = omp_get_num_threads(); /* Read command-line arguments */ switch(argc) { case 4: { seed = atoi(argv[3]); } /* fall thru */ case 3: { N = atoi(argv[2]); if (N < 1 || N > MAXN) { printf("N = %i is out of range.\n", N); exit(0); } } case 2: { procs = atoi(argv[1]); } break; default: { printf("Usage:\n"); printf(" %s <num_processors> <matrix_dimension> [random seed]\n", argv[0]); printf(" %s submit\n", argv[0]); exit(0); } } omp_set_num_threads(procs); srand(seed); /* Randomize */ /* Print parameters */ printf("Matrix dimension N = %i.\n", N); printf("Number of processors P = %i.\n", procs); printf("Random seed = %i\n", seed); }
void Matriz::iniciar (Juego &game) { /*Inicia matriz de juego, Modifica el atributo Cuadrado.mina * de acuerdo al atributo Juego.prob de manera aleatoria * Notese el uso previo de la funcion vector.resize para modificar el tamaño * del vector de vectores y el uso del iterador. */ _matriz.resize (_fil); for (std::vector<std::vector<Cuadrado> >::iterator it = _matriz.begin(); it != _matriz.end(); ++it) { it->resize (_col); } time_t t; for (int i=0; i<_fil;i++) { for (int j=0; j<_col; j++) { srand(time_seed()+i*i-j); float x = static_cast <float> (rand()) / static_cast <float> (RAND_MAX); if (x < game.get_prob() ) { _matriz[i][j].set_mina(true); game.set_cuantas_minas( game.get_cuantas_minas() +1); } } } vecindad(); }
void parameters(int argc, char **argv) { /* <submit> is set to 1 if submission parameters are used. */ int submit = 0; /* Random seed. */ int seed = 0; /* <L_cuserid> is a macro defined in stdio.h */ /* <uid> contains the user name. */ char uid[L_cuserid + 2]; /* Randomise. */ srand(time_seed()); /* Read command-line arguments. */ if (argc != 3) { if (argc == 2 && !strcmp(argv[1], "submit")) { /* Use submission parameters. */ submit = 1; N = 4; NumThreads = 2; printf("Submission run for \"%s\".\n", cuserid(uid)); srand(uid[0]); } else { if (argc == 4) { seed = atoi(argv[3]); srand(seed); printf("Random seed = %d.\n", seed); } else { printf("Usage: %s <matrix_dimension> <num_threads> \ [random seed]\n", argv[0]); printf(" %s submit\n", argv[0]); exit(0); } } } /* Interpret command-line arguments. */ if (!submit) { N = atoi(argv[1]); if (N < 1 || N > MAXN) { printf("N = %d is out of range.\n", N); exit(0); } NumThreads = atoi(argv[2]); if (NumThreads < 1) { printf("Warning: Invalid number of threads = %d. Using 1.\n", NumThreads); NumThreads = 1; } if (NumThreads > _POSIX_THREAD_THREADS_MAX) { printf("Warning: %d threads requested; only %d available.\n", NumThreads, _POSIX_THREAD_THREADS_MAX); NumThreads = _POSIX_THREAD_THREADS_MAX; } } /* Print parameters. */ printf("Matrix dimension N = %d.\n", N); printf("Number of threads = %d.\n", NumThreads); }
generator() { time_seed(); }
extern "C" LEVMARDLL_API void StochFit(BoxReflSettings* InitStruct, double parameters[], double covararray[], int paramsize, double info[], double ParamArray[], double chisquarearray[], int* paramarraysize) { FastReflcalc Refl; Refl.init(InitStruct); double* Reflectivity = InitStruct->Refl; int QSize = InitStruct->QPoints; double* parampercs = InitStruct->ParamPercs; //Setup the fit double opts[LM_OPTS_SZ]; opts[0]=LM_INIT_MU; opts[1]=1E-15; opts[2]=1E-15; opts[3]=1E-20; opts[4]=-LM_DIFF_DELTA; // relevant only if the finite difference jacobian version is used //Allocate a dummy array - Our real calculation is done in Refl.objective double* xvec = new double[InitStruct->QPoints] ; for(int i = 0; i < InitStruct->QPoints; i++) { xvec[i] = 0; } //Copy starting solution double* origguess = new double[paramsize]; memcpy(origguess, parameters, sizeof(double)*paramsize); if(InitStruct->OneSigma) Refl.mkdensityonesigma(parameters, paramsize); else Refl.mkdensity(parameters, paramsize); Refl.myrfdispatch(); double bestchisquare = 0; for(int i = 0; i < InitStruct->QPoints; i++) { bestchisquare += (log(Refl.reflpt[i])-log(Reflectivity[i]))*(log(Refl.reflpt[i])-log(Reflectivity[i])); } double tempinfoarray[9]; tempinfoarray[1] = bestchisquare; double* tempcovararray = new double[paramsize*paramsize]; memset(tempcovararray,0.0, sizeof(double)*paramsize*paramsize); ParameterContainer original(parameters, tempcovararray, paramsize,InitStruct->OneSigma, tempinfoarray, parampercs[6]); delete[] tempcovararray; vector<ParameterContainer> temp; temp.reserve(6000); omp_set_num_threads(omp_get_num_procs()); #pragma omp parallel { FastReflcalc locRefl; locRefl.init(InitStruct); //Initialize random number generator int seed = time_seed(); CRandomMersenne randgen(time_seed()+omp_get_thread_num()); ParameterContainer localanswer; double locparameters[20]; double locbestchisquare = bestchisquare; double bestparam[20]; int vecsize = 1000; int veccount = 0; ParameterContainer* vec = (ParameterContainer*)malloc(vecsize*sizeof(ParameterContainer)); double locinfo[9]; //Allocate workspace - these will be private to each thread double* work, *covar; work=(double*)malloc((LM_DIF_WORKSZ(paramsize, QSize)+paramsize*QSize)*sizeof(double)); covar=work+LM_DIF_WORKSZ(paramsize, QSize); #pragma omp for schedule(runtime) for(int i = 0; i < InitStruct->Iterations;i++) { locparameters[0] = randgen.IRandom(origguess[0]*parampercs[4], origguess[0]*parampercs[5]); for(int k = 0; k< InitStruct->Boxes; k++) { if(InitStruct->OneSigma) { locparameters[2*k+1] = randgen.IRandom(origguess[2*k+1]*parampercs[0], origguess[2*k+1]*parampercs[1]); locparameters[2*k+2] = randgen.IRandom(origguess[2*k+2]*parampercs[2], origguess[2*k+2]*parampercs[3]); } else { locparameters[3*k+1] = randgen.IRandom(origguess[3*k+1]*parampercs[0], origguess[3*k+1]*parampercs[1]); locparameters[3*k+2] = randgen.IRandom(origguess[3*k+2]*parampercs[2], origguess[3*k+2]*parampercs[3]); locparameters[3*k+3] = randgen.IRandom(origguess[3*k+3]*parampercs[4], origguess[3*k+3]*parampercs[5]); } } locparameters[paramsize-1] = origguess[paramsize-1]; if(InitStruct->UL == NULL) dlevmar_dif(locRefl.objective, locparameters, xvec, paramsize, InitStruct->QPoints, 500, opts, locinfo, work,covar,(void*)(&locRefl)); else dlevmar_bc_dif(locRefl.objective, locparameters, xvec, paramsize, InitStruct->QPoints, InitStruct->LL, InitStruct->UL, 500, opts, locinfo, work,covar,(void*)(&locRefl)); localanswer.SetContainer(locparameters,covar,paramsize,InitStruct->OneSigma,locinfo, parampercs[6]); if(locinfo[1] < bestchisquare && localanswer.IsReasonable()) { //Resize the private arrays if we need the space if(veccount+2 == vecsize) { vecsize += 1000; vec = (ParameterContainer*)realloc(vec,vecsize*sizeof(ParameterContainer)); } bool unique = true; int arraysize = veccount; //Check if the answer already exists for(int i = 0; i < arraysize; i++) { if(localanswer == vec[i]) { unique = false; i = arraysize; } } //If the answer is unique add it to our set of answers if(unique) { vec[veccount] = localanswer; veccount++; } } } #pragma omp critical (AddVecs) { for(int i = 0; i < veccount; i++) { temp.push_back(vec[i]); } } free(vec); free(work); } // delete[] xvec; delete[] origguess; //Sort the answers //Get the total number of answers temp.push_back(original); vector<ParameterContainer> allsolutions; allsolutions.reserve(6000); int tempsize = temp.size(); allsolutions.push_back(temp[0]); for(int i = 1; i < tempsize; i++) { int allsolutionssize = allsolutions.size(); for(int j = 0; j < allsolutionssize;j++) { if(temp[i] == allsolutions[j]) { break; } if(j == allsolutionssize-1) { allsolutions.push_back(temp[i]); } } } if(allsolutions.size() > 0) { sort(allsolutions.begin(), allsolutions.end()); } for(int i = 0; i < allsolutions.size() && i < 1000 && allsolutions.size() > 0; i++) { for(int j = 0; j < paramsize; j++) { ParamArray[(i)*paramsize+j] = (allsolutions.at(i).GetParamArray())[j]; covararray[(i)*paramsize+j] = (allsolutions.at(i).GetCovarArray())[j]; } memcpy(info, allsolutions.at(i).GetInfoArray(), 9* sizeof(double)); info += 9; chisquarearray[i] = (allsolutions.at(i).GetScore()); } *paramarraysize = min(allsolutions.size(),999); }
void sfmt_init_fast_r(sfmt_t *sfmt){ struct timeval tp; sfmt_init_gen_rand(sfmt,time_seed()); }
int GetDropConfigurationItem(int OriginalDropRate, int cMapId, int wMonsterLv, int wMonsterId) { //Checking Values if (wMonsterId==0) { wMonsterId=1; } if (wMonsterLv==0) { wMonsterLv=1; } //Loading Initial array with values int ItemDropList[MaximumDropBuffer]; int ItemFoundCounter = 0; //Will be subarray for actual drop int ItemDropFinal[MaximumDropBuffer]; int ItemDropCounter = 0; //Random used variables int HighestDropRate = 0; int NewDropRate = 0; int TempDropRate = 0; int FinalItemPosition = 0; //Log Portion char sBuf[255] = {0}; //Getting all items with the value that is less or equals to the drop rate if (ItemHighestDropRate>=OriginalDropRate) { for(int i=0;i<nDropRateCount;i++) { if (i<MaximumDropBuffer) { if(((DropRateConfig[i].DropMap == -1) || (DropRateConfig[i].DropMap == cMapId)) && ((wMonsterLv>=DropRateConfig[i].Minlvl) && (wMonsterLv<=DropRateConfig[i].Maxlvl))) { if(OriginalDropRate <= DropRateConfig[i].Rate) { ItemDropList[ItemFoundCounter]=i; ItemFoundCounter += 1; } } } } } else { ItemFoundCounter=0; } if (ItemFoundCounter>0) { //wsprintf(sBuf, "[Drop System][Rate: %d][Found: %d][Level: %d][ID: %d] Preparing to drop Item...",OriginalDropRate,ItemFoundCounter,wMonsterLv,wMonsterId); //LogLine("%s\n", sBuf); //Getting Highest Drop rate from new array //===================================================================== for(int i=0;i<ItemFoundCounter;i++) { //Getting Drop Rate of the selected item list TempDropRate=DropRateConfig[ItemDropList[i]].Rate; //Checking if Drop Rate is Higher than previous item if (TempDropRate>HighestDropRate) { HighestDropRate=TempDropRate; } } //Generating New drop % from the range //===================================================================== if (HighestDropRate>1) { srand(time_seed()+wMonsterLv+wMonsterId); NewDropRate = (rand()/(((double)RAND_MAX + 1)/HighestDropRate)); if (NewDropRate>OriginalDropRate) { NewDropRate=NewDropRate/2; } else if (NewDropRate==0) { srand(time_seed()*wMonsterLv*wMonsterLv/wMonsterId); NewDropRate = (rand()/(((double)RAND_MAX + 1)/HighestDropRate)); } } //Getting new set of items from the Array with higher drop rate //===================================================================== for(int i=0;i<ItemFoundCounter;i++) { if (i<MaximumDropBuffer) { if(NewDropRate <= DropRateConfig[ItemDropList[i]].Rate) { ItemDropFinal[ItemDropCounter]=ItemDropList[i]; ItemDropCounter += 1; } } } if (ItemDropCounter>0) { if (ItemDropCounter>1) { //Generating a random items from array //===================================================================== srand(time_seed()*wMonsterId/wMonsterLv); FinalItemPosition = rand()/(((double)RAND_MAX + 1)/ItemDropCounter); if (FinalItemPosition==PreviousItemPosition) { srand(time_seed()-wMonsterId+wMonsterLv); FinalItemPosition = rand()/((RAND_MAX + 1)/ItemDropCounter); } } else { FinalItemPosition = 0; } FinalItemPosition = FinalItemPosition+1; PreviousItemPosition = FinalItemPosition; // wsprintf(sBuf, "[Drop System][GET ITEM] Start Rate: %d / Found Items: %d / Highest Rate: %d / New Rate: %d / Drop Items: %d / Drop Index: %d[%d]",OriginalDropRate,ItemFoundCounter,HighestDropRate,NewDropRate,ItemDropCounter,ItemDropFinal[FinalItemPosition-1],FinalItemPosition-1); // LogLine("%s\n", sBuf); //Returning the item //===================================================================== return ItemDropFinal[FinalItemPosition-1]; } else { return -1; } } else { //Return -1 if item has not been found //===================================================================== return -1; } }