void DESolver::Setup( double *min, double *max, int deStrategy, double diffScale, double crossoverProb, double ftol, unsigned long rngSeed ) { int i; strategy = deStrategy; scale = diffScale; probability = crossoverProb; tolerance = ftol; // PE: seed the (Mersenne Twister) RNG if (rngSeed > 0) init_genrand(rngSeed); else init_genrand((unsigned long)time((time_t *)NULL)); CopyVector(minBounds, min); CopyVector(maxBounds, max); for (i = 0; i < nPop; i++) { for (int j = 0; j < nDim; j++) Element(population,i,j) = RandomUniform(min[j], max[j]); popEnergy[i] = 1.0E20; } for (i = 0; i < nDim; i++) bestSolution[i] = 0.0; }
int main ( int argc, char * const argv[] ) { printf( "Testing output and speed of inventors' Mersenne Twister program\n" ); printf( "\nTest of random integer generation:\n" ); unsigned long oneSeed = 4357UL; unsigned long bigSeed[4] = { 0x123UL, 0x234UL, 0x345UL, 0x456UL }; printf( "\nTest of random integer generation:\n" ); init_by_array( bigSeed, 4 ); unsigned long i; for( i = 0; i < 1000UL; ++i ) { printf( "%10lu ", genrand_int32() ); if( i % 5 == 4 ) printf("\n"); } printf( "\nTest of random real number [0,1) generation:\n" ); for( i = 0; i < 1000UL; ++i ) { printf( "%10.8f ", genrand_real2() ); if( i % 5 == 4 ) printf("\n"); } printf( "\nTest of random real number [0,1] generation:\n" ); init_genrand( oneSeed ); for( i = 0; i < 2000UL; ++i ) { printf( "%10.8f ", genrand_real1() ); if( i % 5 == 4 ) printf("\n"); } printf( "\nTest of time to generate one billion random integers:\n" ); init_genrand( oneSeed ); unsigned long junk = 0; clock_t start = clock(); for( i = 0; i < 1000000000UL; ++i ) { junk ^= genrand_int32(); } clock_t stop = clock(); if( junk == 0 ) printf( "jinx\n" ); printf( "Time elapsed = " ); printf( "%8.3f", double( stop - start ) / CLOCKS_PER_SEC ); printf( " s\n" ); return 0; }
void ndice() { char* buffer; int a[6]; int i = 0; int m = 0; int n = 0; int t = 0; buffer = open_minibuffer("Number of dice: "); m = atoi(buffer); for(i = 0; i < 6; ++i) a[i] = 0; init_genrand((unsigned)time(NULL)); for(i = 0; i < m; ++i) { t = (int)(genrand_real1() * 6); a[t]++; n += t + 1; } for(i = 0; i < COLS; ++i) mvaddch(LINES - 1, i, ' '); for(i = 0; i < 6; ++i) mvprintw(LINES - 1, i * 6, "%d:% 3d", i + 1, a[i]); mvprintw(LINES - 1, 0, "%d: %d %d: %d %d: %d %d: %d %d: %d " "%d: %d Total: %d", 1, a[0], 2, a[1], 3, a[2], 4, a[3], 5, a[4], 6, a[5], n); }
inline void InitRand(unsigned long seed) { #ifdef STANDARD_RAND srand(seed); #else init_genrand(seed); #endif }
int main(int argc, char *argv[]) { init_genrand(0); hls::stream<uint32_t> uniform_rns; hls::stream<float> gaussian_rns; const int N = 1000; uint32_t arn[N]; for (int i = 0; i < N; ++i) { uint32_t rn = genrand_int32(); arn[i] = rn; uniform_rns.write(rn); } for (int i = 0; i < N; ++i) icdf(uniform_rns, gaussian_rns); int i = 0; while (gaussian_rns.size() > 0) { float acc_res = gaussian_rns.read(); std::cout << i << ": " << acc_res << std::endl; ++i; } std::cout << "done." << std::endl; return 0; }
/******************************************************** MAIN *********************************************************/ int main(void) { int map[XMAX][YMAX], bmap[XMAX][YMAX][2]; SPLAYER player; LPTCB task; floor_cnt = 1; init_genrand((unsigned long)time(NULL)); // 必ずmainに入れること init_task(); init_monster(); task = create_task(title_load, NULL, PRIO_00); task->p[0] = &player; task->p[1] = &floor_cnt; task = create_task(game_start, NULL, PRIO_00); task->p[0] = map; task->p[1] = &player; task->p[2] = bmap; loop_task(); // printf("taskcnt =%d\n", count_task()); return 0; }
// Zipf分布によるランダムなCommonData名前決定 uint16_t GlobalNodeData::return_MsgName() { double target; uint32_t top, bottom, mid; static BOOL INIT_RAND = false; if(!INIT_RAND) { init_genrand((unsigned)time(NULL)); INIT_RAND = true; } target = genrand_real1(); top = file_size; while(bottom < top) { mid = (bottom + top) / 2; if(this->Zipf[(uint16_t)mid] == target) { break; } else if(this->Zipf[(uint16_t)mid] < target) { bottom = mid + 1; } else { top = mid - 1; } if(mid == 0) break; if(mid == file_size) break; } // 動画コンテンツ名前と重複する場合、ずらす if(mid == 10000) mid++; return (uint32_t)mid; }
void kmain(multiboot_info_t* mbd, unsigned int magic){ // kernel entry point. //unsigned char* videoram = (unsigned char*) 0xb8000; //videoram[0] = 65; //videoram[1] = 0x07; //setMode(0x13); setMode(320, 200, 8); // HOLY SHIT THIS WORKS clrscr(); gdt_install(); idt_install(); isrs_install(); irq_install(); timer_install(); start_paging(mbd); keyboard_install(); init_genrand(get_timer_ticks()); __asm__ __volatile__ ("sti"); kprint("Hello, We have booted successfully!\n\tTip: type help for command info\n"); while(1){ if(todo != NULL){ void(*function)() = todo; function(todoCP); todo = NULL; } } }
int main(int argc, char *argv[]) { // generate seeds uint32_t seeds[624]; init_genrand(0); generate_numbers(); get_mt_state(seeds); // get hardware random numbers hls::stream<uint32_t> random_numbers; mersenne_twister(seeds, random_numbers); // compare with software model for (int i = 0; i < 1000 - 396 - 1; ++i) { uint32_t rn_sw = genrand_int32(); uint32_t rn_hw = random_numbers.read(); if (rn_sw != rn_hw) { std::cout << i << ": " << rn_sw << " != " << rn_hw << std::endl; return -1; } } std::cout << "test passed." << std::endl; return 0; }
static void test_generalized_dimension (struct test_solver_info *ts_info) { if (ts_info->length <= 0 || ts_info->dim < 1) return; int box_num, *box_count; MALLOC(box_count, ts_info->length); init_genrand(5747L); for (int n = 0; n < ts_info->length; n++) { ts_info->data[n][0] = genrand_real1(); } int dnum = 10; double dimension[dnum]; for (int q = 0; q < dnum; q++) { dimension[q] = generalized_dimension( (const double* const*)ts_info->data, ts_info->length, 1, 1e-2, q, &box_num); } for (int q = 1; q < dnum; q++) { mu_assert(dimension[q-1] >= dimension[q]); } FREE(box_count); }
static int Lnew(lua_State *L) /** new([seed]) */ { long seed=luaL_optlong(L,1,SEED); MT *c=Pnew(L); init_genrand(c,seed); return 1; }
int main(int argc, char **argv) { if(sizeof(int) != 4) { fprintf(stderr, "Your machine's ints are not 4 bytes. " "You need to adjust generate_data() and check_data().\n"); exit(2); } process_args(argc, argv); init_genrand(opt_seed); if(opt_check) { check_data(0, opt_size); } else { generate_data(1, opt_size); } /* int i; printf("1000 outputs of genrand_int32()\n"); for (i=0; i<1000; i++) { printf("%10lu ", genrand_int32()); if (i%5==4) printf("\n"); } */ return 0; }
double RunQILGP() { unsigned int i; //srand((unsigned int)time(NULL)); // 0 to 4,294,967,295 (4294967295) //srand(3221225472); init_genrand((unsigned long)time(NULL)); //init_genrand(0); //0//1073741824//2147483648//3221225472//-//536870912//1610612736//2684354560//3758096384 writeFreq = nGenerations / 100; indivLen = (headerLen + qIndivLen * mCodeDim + footerLen); InitSintaticTable(); InitIndiv(); accumFit = malloc(nGenerations / writeFreq * sizeof(double)); accumValFit = malloc(nGenerations / writeFreq * sizeof(double)); accumLen = malloc(nGenerations / writeFreq * sizeof(double)); for (i = 0; i < (nGenerations / writeFreq); i++) { accumFit[i] = 0; accumValFit[i] = 0; accumLen[i] = 0; } nEvaluations = 0; bestTkIndiv.error = HUGE_VAL; bestTkIndiv.fitness = HUGE_VAL; bestTkIndiv.validFitness = HUGE_VAL; bestTkIndiv.genome = malloc(qIndivLen * sizeof(int) * 2); return RunMultiQILGP(); }
int *generate_random_sol(tm_topology_t *topology,int N,int level,int seed) { hash_t *hash_tab = NULL; int *sol = NULL; int *nodes_id= NULL; int i; nodes_id = topology->node_id[level]; hash_tab = (hash_t*)MALLOC(sizeof(hash_t)*N); sol = (int*)MALLOC(sizeof(int)*N); init_genrand(seed); for( i = 0 ; i < N ; i++ ){ hash_tab[i].val = nodes_id[i]; hash_tab[i].key = genrand_int32(); } qsort(hash_tab,N,sizeof(hash_t),hash_asc); for( i = 0 ; i < N ; i++ ) sol[i] = hash_tab[i].val; FREE(hash_tab); return sol; }
static int Lseed(lua_State *L) /** seed(c,[seed]) */ { MT *c=Pget(L,1); init_genrand(c,luaL_optnumber(L,2,SEED)); lua_settop(L,1); return 1; }
int main(int argc, char *argv[]) { int size, j, p; init_genrand(0UL); for (p = 512; p >= 500; p--) { size = p; double *A = new double[size * size]; double *U = new double[size * size]; double *VT = new double[size * size]; double *S = new double[size]; if (A == NULL) { printf("Out of Memory!!\n"); exit(1); } for (j = 0; j < size * size; j++) A[j] = genrand_real1(); for (j = 0; j < size * size; j++) U[j] = genrand_real1(); for (j = 0; j < size * size; j++) VT[j] = genrand_real1(); for (j = 0; j < size; j++) S[j] = genrand_real1(); bench_gesdd(size, A, U, VT, S); delete[]S; delete[]VT; delete[]U; delete[]A; } return 0; }
int main(){ int nset=NSETS; int ndata=ARRAY_LENGTH; int hash_size=HASH_SIZE; /* double* data; */ double** data2d; char *sdata = "hoge"; /* unsigned long hash,hash2,hash3,hash4; */ unsigned long* hash; unsigned long* hash2; unsigned long* hash3; unsigned long* hash4; int i,j; data2d=(double**) malloc(sizeof(double*)*nset); hash=(unsigned long*) malloc(sizeof(unsigned long)*nset); hash2=(unsigned long*) malloc(sizeof(unsigned long)*nset); hash3=(unsigned long*) malloc(sizeof(unsigned long)*nset); hash4=(unsigned long*) malloc(sizeof(unsigned long)*nset); for(i=0;i<nset;i++){ data2d[i]=(double*) malloc(sizeof(double)*ndata); } /*data=(double*) malloc(sizeof(double)*ndata);*/ init_genrand(194743097); for(j=0;j<nset;j++){ for(i=0;i<ndata;i++){ /* data[i]=genrand_res53(); */ data2d[j][i]=genrand_res53(); } /* hash=adhf_1(data,ndata,hash_size); */ /* hash2=adhf_2(data,ndata,hash_size); */ /* hash3=adhf_3(data,ndata,hash_size); */ /* hash4=adhf_4(data,ndata,hash_size); */ /* printf("%d %d %d %d\n",hash,hash2,hash3,hash4); */ } /*omp parallel start*/ #pragma omp parallel for for(j=0;j<nset;j++){ hash[j]=adhf_1(data2d[j],ndata,hash_size); hash2[j]=adhf_2(data2d[j],ndata,hash_size); hash3[j]=adhf_3(data2d[j],ndata,hash_size); hash4[j]=adhf_4(data2d[j],ndata,hash_size); } /*omp parallel end*/ for(j=0;j<nset;j++){ printf("%d %d %d %d\n",hash[j],hash2[j],hash3[j],hash4[j]); } }
int main(int argc, char *argv[]) { if (argc < 8) { fprintf(stderr, "usage:\t%s <size A> <len A> <size B> <len B> " "<seed> <P> <size I>\n", argv[0]); return 1; } unsigned int size_A = atoi(argv[1]); unsigned int len_A = atoi(argv[2]); unsigned int size_B = atoi(argv[3]); unsigned int len_B = atoi(argv[4]); unsigned int seed = atoi(argv[5]); unsigned int P = atoi(argv[6]); unsigned int size_I = atoi(argv[7]); unsigned int size_T = size_I; if (size_I > size_B) { fprintf(stderr, "Index larger than DB.\n"); return 1; } struct interval *A = (struct interval *) malloc(size_A * sizeof(struct interval)); struct interval *B = (struct interval *) malloc(size_B * sizeof(struct interval)); unsigned int *R = (unsigned int *) malloc(size_A * sizeof(unsigned int)); init_genrand(seed); generate_interval_sets(A, size_A, len_A, B, size_B, len_B, P); start(); unsigned int O = per_interval_count_intersections_bsearch_seq( A, size_A, B, size_B, R); stop(); unsigned long bsearch_time = report(); /* start(); unsigned int OB = count_intersections_brute_force_seq(A, size_A, B, size_B); stop(); unsigned long brute_force_time = report(); */ int i; for (i = 0; i < size_A; i++) if (R[i] != 0) printf("%d\t%u\n", i, R[i]); printf("b:%u,%lu\n", O, bsearch_time); }
int main(int argc, char **argv) { int i; struct details details; struct gges_population *pop; struct gges_parameters *params; struct gges_bnf_grammar *G; char bufvar[255]; struct timeval t; gettimeofday(&t, NULL); init_genrand(t.tv_usec); details.b = atoi(argv[2]); details.n = 1 << details.b; details.data = generate_data(details.b); params = gges_default_parameters(); params->rnd = genrand_real2; i = 3; while (i < argc) { if (strncmp(argv[i], "-p", 2) == 0) { process_parameter(argv[i + 1], params); i += 2; } else { parse_parameters(argv[i++], params); } } G = gges_load_bnf(argv[1]); /* add the features to the grammar, starting from the second * variable. The current implementation requires us to * "completely" specify the grammar in the source file, meaning * that no non-terminals can be left incomplete, therefore, we * have to include the first variable in the source file, and then * start from the second one */ if (gges_grammar_has_non_terminal(G, "<bit>")) { for (i = 1; i < details.b; ++i) { sprintf(bufvar, "<bit> ::= b%d", i); gges_extend_grammar(G, bufvar, true); } } else { for (i = 1; i < details.b; ++i) { sprintf(bufvar, "<B> ::= b%d", i); gges_extend_grammar(G, bufvar, true); } } pop = gges_run_system(params, G, eval, NULL, report, &details); gges_release_population(pop); free(params); gges_release_grammar(G); free_data(details.data); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { init_genrand(time(NULL)); lab *laboratory = new lab(); get_parameters(argc, argv, laboratory); return 0; }
void Random_Seed(unsigned long int seed) { #if EXTLIB_EXIST(GSL) gsl_rng_init(); gsl_rng_set(Random_Generator, seed); #else init_genrand(seed); #endif }
int main(void) { unsigned long oneSeed = 4357UL; unsigned long bigSeed[4] = { 0x123, 0x234, 0x345, 0x456 }; printf( "Testing output and speed of mt19937ar-c*k.c\n" ); printf( "\nTest of random integer generation:\n" ); init_by_array( bigSeed, 4 ); for( i = 0; i < 1000; ++i ) { printf( "%10lu ", genrand_int32() ); if( i % 5 == 4 ) printf("\n"); } printf( "\nTest of random real number [0,1) generation:\n" ); for( i = 0; i < 1000; ++i ) { printf( "%10.8f ", genrand_real2() ); if( i % 5 == 4 ) printf("\n"); } printf( "\nTest of random real number [0,1] generation:\n" ); init_genrand( oneSeed ); for( i = 0; i < 1000; ++i ) { printf( "%10.8f ", genrand_real1() ); if( i % 5 == 4 ) printf("\n"); } printf( "\nTest of time to generate 300 million random integers:\n" ); init_genrand( oneSeed ); start = clock(); for( i = 0; i < 300000000; ++i ) { junk = genrand_int32(); } stop = clock(); printf( "Time elapsed = " ); printf( "%8.3f", (double)( stop - start ) / CLOCKS_PER_SEC ); printf( " s\n" ); return 0; }
static int l_random_seed(lua_State *L) { MT *m = l_checkRandom(L, 1); init_genrand(m, luaL_optnumber(L, 2, time(NULL))); lua_settop(L, 1); return 1; }
void test_rnn_runner (void) { struct test_rnn_runner_data t_data[4]; init_genrand(391919L); mu_run_test(test_new_rnn_runner); mu_run_test_with_args(test_init_rnn_runner, t_data, 1, 10, 1, 1, STANDARD_TYPE, 2, (int[]){50,100});
static int seed_rng (lua_State *L) { nl_RNG *r = getrng(L); if (lua_isnoneornil(L, 1)) init_genrand(r, RNG_SEED); else if (lua_isnumber(L, 1)) /* seed? */ init_genrand(r, lua_tointeger(L, 1)); else { /* vector */ unsigned long initkey[RNG_MAXSTATES]; int i, k; lua_Number *e; nl_Matrix *m = nl_checkmatrix(L, 1); checkrvector(L, m, 1); for (i = 0, e = m->data; i < m->size; i++, e += m->stride) { lua_number2int(k, *e); initkey[i] = (unsigned long) k; } init_by_array(r, initkey, m->size); } return 0; }
void RunSpeedSimulation ( __global int* intStream, int* pCharPos, int cSimulations, int seed ) { //These are needed for FastRandom function calls unsigned long mt[N]; int mti=N+1; SimulationResults results; Board board; double averageResult = 0.0; double blackWinPercentage = 0; int x; SetupBoard(&board); init_genrand(seed, mt, &mti); results.blackPlays = 0; results.whitePlays = 0; for(x = 0; x < cSimulations; x++) { MonteCarloSimulate(&board, genrand_int32(mt, &mti), &results, mt, &mti); averageResult += results.scoreInFavourOfBlack; if(results.scoreInFavourOfBlack > 0) blackWinPercentage++; } WriteStringToIntStream(intStream, pCharPos, "("); WriteFloatToIntStream(intStream, pCharPos, (float)averageResult / cSimulations, 5); WriteStringToIntStream(intStream, pCharPos, ") <average result> with "); WriteStringToIntStream(intStream, pCharPos, "("); WriteFloatToIntStream(intStream, pCharPos, (float)blackWinPercentage / cSimulations, 5); WriteStringToIntStream(intStream, pCharPos, ") <average black win percentage>\n"); WriteStringToIntStream(intStream, pCharPos, "("); WriteFloatToIntStream(intStream, pCharPos, (float)results.blackPlays / cSimulations, 5); WriteStringToIntStream(intStream, pCharPos, ") <average black plays>\n"); WriteStringToIntStream(intStream, pCharPos, "("); WriteFloatToIntStream(intStream, pCharPos, (float)results.whitePlays / cSimulations, 5); WriteStringToIntStream(intStream, pCharPos, ") <average white plays>\n"); }
void init_world() { lcdMainOnBottom(); #ifndef NATIVE // TODO: replace with gettimeofday() or similar init_genrand(genrand_int32() ^ (IPC->time.rtc.seconds + IPC->time.rtc.minutes*60 + IPC->time.rtc.hours*60*60 + IPC->time.rtc.weekday*7*24*60*60)); #else { struct timeval tv; gettimeofday(&tv,NULL); init_genrand(tv.tv_usec+tv.tv_sec*1000000); } #endif new_game(); torch.run(handler); }
void _decrypt(char * pBuffer, size_t size, size_t seed ) { s_mersenne_twister_status mt; size_t i; unsigned long rseed = (seed << 7) ^ 0xA9C36DE1; init_genrand(&mt, rseed); for (i = 0; i < size;i++) { pBuffer[i] = (char)(pBuffer[i] ^ genrand_int32(&mt)); } }
/* ============================================================================= * random_alloc * -- Returns NULL if failure * ============================================================================= */ random_t* random_alloc (void) { random_t* randomPtr = (random_t*)SEQ_MALLOC(sizeof(random_t)); if (randomPtr != NULL) { randomPtr->mti = N; init_genrand(randomPtr->mt, &(randomPtr->mti), RANDOM_DEFAULT_SEED); } return randomPtr; }
void optimum_reparam(double *C1, double *C2, int n, int d, double w, bool onlyDP, bool rotated, bool isclosed, int skipm, int autoselectC, double *opt, bool swap, double *fopts, double *comtime) { /* dimensions of input matrices */ /* opt size is n + d*d +1 */ /* fopts and comtime are 5 x 1*/ integer n1, d1; n1 = static_cast<integer> (n); d1 = static_cast<integer> (d); bool swapi; std::string methodname = ""; if (!onlyDP) methodname = "RBFGS"; init_genrand(0); CheckMemoryDeleted = new std::map<integer *, integer>; integer numofmanis = 3; integer numofmani1 = 1; integer numofmani2 = 1; integer numofmani3 = 1; L2SphereVariable FNSV(n); OrthGroupVariable OGV(d); EucVariable EucV(1); ProductElement *Xopt = new ProductElement(numofmanis, &FNSV, numofmani1, &OGV, numofmani2, &EucV, numofmani3); integer ns, lms; DriverElasticCurvesRO(C1, C2, d1, n1, w, rotated, isclosed, onlyDP, skipm, methodname, autoselectC, Xopt, swapi, fopts, comtime, ns, lms); swap = swapi; /* get output data */ integer sizex = n1 + d1 * d1 + 1; const double *Xoptptr = Xopt->ObtainReadData(); integer inc = 1; dcopy_(&sizex, const_cast<double *> (Xoptptr), &inc, opt, &inc); delete Xopt; std::map<integer *, integer>::iterator iter = CheckMemoryDeleted->begin(); for (iter = CheckMemoryDeleted->begin(); iter != CheckMemoryDeleted->end(); iter++) { if (iter->second != 1) std::cout << "Global address:" << iter->first << ", sharedtimes:" << iter->second << std::endl; } delete CheckMemoryDeleted; return; }