int main(int argc, char **argv) { if(argc <= 1) { cout << "Usage: F++ <file>" << endl; cout << " Loads and runs the befunge program <file>" << endl; return 0; } init_rand(); init_grid(argv[1]); while(_RUN) { char C = _GRID[_Y][_X]; if(C != 0 && (_MODE == _NORMAL || C == '"')) { //cout << "in normal mode, doing op " << C << endl; do_op(C); } else if(C != 0) { //cout << "in string mode, pushing " << C << endl; push(C); } move(); //sleep(1); } cout << endl; return 0; }
int main() { check_clock_support(); init_rand(); init_speed(); with_ncurses(gameloop); return 0; }
int main(void) { unsigned int i; struct avro_tests { char *name; avro_test func; } tests[] = { { "string", test_string}, { "bytes", test_bytes}, { "int", test_int32}, { "long", test_int64}, { "float", test_float}, { "double", test_double}, { "boolean", test_boolean}, { "null", test_null}, { "record", test_record}, { "enum", test_enum}, { "array", test_array}, { "map", test_map}, { "fixed", test_fixed}, { "union", test_union} }; init_rand(); for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) { struct avro_tests *test = tests + i; fprintf(stderr, "**** Running %s tests ****\n", test->name); if (test->func() != 0) { return EXIT_FAILURE; } } return EXIT_SUCCESS; }
int main() { int flag = 0; DDRB = 0xff; DDRC = 0x0f; DDRD = 0xfa; PORTC = 0x30; OCR0A = 249; TCCR0A = 2; TCCR0B = 3; TIMSK0 |= (1 << OCIE0A); TCCR2A = 0x12; TCCR2B = 0x04; OCR2A = 238; n = rand() % N; sei(); while(1){ wdt_reset(); // ウォッチドッグタイマのリセット if(flag == 0){ init_rand(); n = rand() % N; if(SW == 0x01) flag = 1; }else{ if(SW == 0x01) n = rand() % N; } } return 0; }
void damgard_jurik::encrypt(damgard_jurik_ciphertext_t **list, damgard_jurik_plaintext_t **text, unsigned long s, int size) { mpz_t r; gmp_randstate_t rand; mpz_t x; mpz_t gc; /* pick random blinding factor */ mpz_init(r); mpz_init(gc); init_rand(rand, pubkey->bits / 8 + 1); do { mpz_urandomb(r, rand, pubkey->bits); mpz_gcd(gc, r, pubkey->n); }while (mpz_cmp(r, pubkey->n) >= 0 || mpz_cmp_ui(gc, 1) > 0 || mpz_cmp_ui(r, 0) == 0); mpz_init(x); mpz_powm(x, r, pubkey->n_j[s], pubkey->n_j[s + 1]); for (int i = 0; i < size; i++) { list[i] = new damgard_jurik_ciphertext_t(); // mpz_powm(list[i]->text, pubkey->g, text[i]->text, pubkey->n_j[s + 1]); compute_exp(&list[i]->text, &text[i]->text, s); mpz_mul(list[i]->text, list[i]->text, x); mpz_mod(list[i]->text, list[i]->text, pubkey->n_j[s + 1]); mpz_set(list[i]->n_s, pubkey->n_j[s + 1]); list[i]->s = s; } mpz_clear(x); mpz_clear(r); gmp_randclear(rand); }
damgard_jurik_ciphertext_t* damgard_jurik::encrypt(damgard_jurik_plaintext_t* pt, unsigned long s) { mpz_t r; gmp_randstate_t rand; mpz_t x; mpz_t gc; damgard_jurik_ciphertext_t *res = new damgard_jurik_ciphertext_t(); /* pick random blinding factor */ mpz_init(r); mpz_init(gc); init_rand(rand, pubkey->bits / 8 + 1); do { mpz_urandomb(r, rand, pubkey->bits); mpz_gcd(gc, r, pubkey->n); }while( mpz_cmp(r, pubkey->n) >= 0 || mpz_cmp_ui(gc, 1) > 0 || mpz_cmp_ui(r, 0) == 0); mpz_init(x); // mpz_powm(res->text, pubkey->g, pt->text, pubkey->n_j[s + 1]); compute_exp(&res->text, &pt->text, s); mpz_powm(x, r, pubkey->n_j[s], pubkey->n_j[s + 1]); mpz_mul(res->text, res->text, x); mpz_mod(res->text, res->text, pubkey->n_j[s + 1]); mpz_set(res->n_s, pubkey->n_j[s + 1]); res->s = s; mpz_clear(x); mpz_clear(r); gmp_randclear(rand); return res; }
int main(void) { subscribe_signals(); init_rand(); if (!create_loader(&loader)) { fprintf(stderr, "No point loader specified\n"); return 1; } sslog_init(); register_ontology(); static char kp_name[1000]; snprintf(kp_name, sizeof(kp_name), "geo_kp_%s", loader.get_name()); sslog_node_t* node = create_node(kp_name, "config.ini"); if (sslog_node_join(node) != SSLOG_ERROR_NO) { fprintf(stderr, "Can't join node\n"); return 1; } geo_common_serve_kp(node, loader); sslog_sbcr_unsubscribe_all(node, true); sslog_node_leave(node); sslog_shutdown(); }
void DS::CryptEstablish(uint8_t* seed, uint8_t* key, const uint8_t* N, const uint8_t* K, uint8_t* Y) { BIGNUM* bn_Y = BN_new(); BIGNUM* bn_N = BN_new(); BIGNUM* bn_K = BN_new(); BIGNUM* bn_seed = BN_new(); BN_CTX* ctx = BN_CTX_new(); /* Random 7-byte server seed */ init_rand(); RAND_bytes(reinterpret_cast<unsigned char*>(seed), 7); /* client = Y ^ K % N */ BN_bin2bn(reinterpret_cast<const unsigned char*>(Y), 64, bn_Y); BN_bin2bn(reinterpret_cast<const unsigned char*>(N), 64, bn_N); BN_bin2bn(reinterpret_cast<const unsigned char*>(K), 64, bn_K); DS_PASSERT(!BN_is_zero(bn_N)); BN_mod_exp(bn_seed, bn_Y, bn_K, bn_N, ctx); /* Apply server seed for establishing crypt state with client */ uint8_t keybuf[64]; DS_DASSERT(BN_num_bytes(bn_seed) <= 64); size_t outBytes = BN_bn2bin(bn_seed, reinterpret_cast<unsigned char*>(keybuf)); BYTE_SWAP_BUFFER(keybuf, outBytes); for (size_t i=0; i<7; ++i) key[i] = keybuf[i] ^ seed[i]; BN_free(bn_Y); BN_free(bn_N); BN_free(bn_K); BN_free(bn_seed); BN_CTX_free(ctx); }
/** * Return this thread's random number generator, creating it if it doesn't * yet exist. */ std::default_random_engine* get_generator() { if (generator == NULL) { generator = init_rand(); } return generator; }
int random_int(int a, int b) { init_rand(); #ifdef HAVE_LIBGSL return ((int) gsl_rng_uniform_int(rng, b-a+1)) + a; #else return a + rand() % (b-a+1); #endif }
double uniform_random(double a, double b) { init_rand(); #ifdef HAVE_LIBGSL return a + gsl_rng_uniform(rng) * (b-a); #else return a + rand() * (b-a) / RAND_MAX; #endif }
void paillier_keygen( int modulusbits, paillier_pubkey_t** pub, paillier_prvkey_t** prv, paillier_get_rand_t get_rand ) { mpz_t p; mpz_t q; gmp_randstate_t rand; /* allocate the new key structures */ *pub = (paillier_pubkey_t*) malloc(sizeof(paillier_pubkey_t)); *prv = (paillier_prvkey_t*) malloc(sizeof(paillier_prvkey_t)); /* initialize our integers */ mpz_init((*pub)->n); mpz_init((*pub)->n_squared); mpz_init((*pub)->n_plusone); mpz_init((*prv)->lambda); mpz_init((*prv)->x); mpz_init(p); mpz_init(q); /* pick random (modulusbits/2)-bit primes p and q */ init_rand(rand, get_rand, modulusbits / 8 + 1); do { do mpz_urandomb(p, rand, modulusbits / 2); while( !mpz_probab_prime_p(p, 10) ); do mpz_urandomb(q, rand, modulusbits / 2); while( !mpz_probab_prime_p(q, 10) ); /* compute the public modulus n = p q */ mpz_mul((*pub)->n, p, q); } while( !mpz_tstbit((*pub)->n, modulusbits - 1) ); complete_pubkey(*pub); (*pub)->bits = modulusbits; /* compute the private key lambda = lcm(p-1,q-1) */ mpz_sub_ui(p, p, 1); mpz_sub_ui(q, q, 1); mpz_lcm((*prv)->lambda, p, q); complete_prvkey(*prv, *pub); /* clear temporary integers and randstate */ mpz_clear(p); mpz_clear(q); gmp_randclear(rand); }
void random_prime(mpz_t prime, unsigned long num_bits) { if (!rand_initialized) { init_rand(); } mpz_urandomb(prime, randstate, num_bits); mpz_nextprime(prime, prime); }
void set_random_seed(unsigned long seed) { init_rand(); seed = ((unsigned long) broadcast(0, (int) seed)) + my_rank(); #ifdef HAVE_LIBGSL gsl_rng_set(rng, seed); #else srand(seed); #endif }
void main(void) { int nFrame, nStay; int x, y; SetCursorType(NOCURSOR), init_rand(); for (; 1;) // 게임이 끝났을 경우 다시 시작하거나 끝내는 루프 { Score = 0, bricknum = 0; CLS; // 무한루프에 들어가기전 초기화 for (x = 0; x < BW + 2; x++) // 외부벽 초기화 { for (y = 0; y < BH + 2; y++) { board[x][y] = (y == 0 || y == BH + 1 || x == 0 || x == BW + 1) ? WALL : EMPTY; } } DrawScreen(); nFrame = 10; nbrick = make_rand(sizeof(Shape) / sizeof(Shape[0])); for (; 2;) // 전체 게임 루프 { bricknum++; brick = nbrick; nbrick = make_rand(sizeof(Shape) / sizeof(Shape[0])); // 새 벽돌 생성 DrawNext(); //DrawPresent() nx = BW / 2, ny = 2; rot = 0; PrintBrick(TRUE); if (GetAround(nx, ny, brick, rot) != EMPTY) break; // 게임 끝 점검 nStay = nFrame; for (; 3;) // 벽돌 하나 처리 루프 { if (--nStay == 0) { nStay = nFrame; if (MoveDown()) break; // 벽돌 내림 } if (ProcessKey()) break; // 키처리 delay(1000 / 20); // 시간 지연 } if (bricknum % 5 == 0 && nFrame > 3) nFrame--; } CLS; gotoxy(30, 12), puts("G A M E O V E R"); // 게임 끝 처리 gotoxy(23, 14), puts("If you want restart game press [ Y ]"); // 재시작 gotoxy(27, 16), puts("another any key [ Exit ]"); if (tolower(getch()) != 'y') break; } SetCursorType(NORMALCURSOR); }
paillier_ciphertext_t* paillier_enc(paillier_tag* tag, paillier_ciphertext_t* res, paillier_pubkey_t* pub, paillier_plaintext_t* pt, paillier_get_rand_t get_rand, int no_copies, mpz_t* rand_prf) { mpz_t r; gmp_randstate_t rand; mpz_t x, one; // char val = '1'; /* pick random blinding factor */ mpz_init(r); mpz_init_set_str(one, "1", 10); //printf("\npubbits : %d \n", pub->bits); init_rand(rand, get_rand, pub->bits / 8 + 1); /* compute ciphertext */ /*if( !res ) { res = (paillier_ciphertext_t*) malloc(sizeof(paillier_ciphertext_t)); mpz_init(res->c); } */ //printf("\n calculating enc"); mpz_t t; mpz_init(x); mpz_init(t); mpz_set(tag->t, pt->m); mpz_mul(t, pub->n, pt->m); int j; for(j=0; j < no_copies; j++) { do mpz_urandomb(r, rand, pub->bits); while( mpz_cmp(r, pub->n) >= 0 ); mpz_mul(r, r, rand_prf[j]); mpz_mod(r, r, pub->n); mpz_powm(x, r, pub->n, pub->n_squared); mpz_init(res[j].c); //printf("\n power %d", j ); mpz_add(res[j].c, one, t); //mpz_powm(res[j].c, pub->n_plusone, pt->m, pub->n_squared); mpz_mul(res[j].c, res[j].c, x); //printf("\n multiply"); mpz_mod(res[j].c, res[j].c, pub->n_squared); } //printf("\n mod"); mpz_clear(x); //printf("\n clear"); mpz_clear(r); gmp_randclear(rand); return res; }
//init simulation, component_num is the total number of component in simulation int init_simulation(int component_num) { int ret = 0; init_rand(); component_size = component_num; component_list = malloc(sizeof(Component*)*component_size); if(component_list==NULL) ret = -1; return ret; }
int main(int argc, char **argv) { init_rand(time(NULL)); periods_vs_avgtime(scenario2); //beaconCount_vs_time(scenario1); //bandwidth_vs_time(scenario1); return 0; }
int main (int argc, char *argv[]) { init_rand(); run_test("/bson/new", test_bson_new); run_test("/bson/init", test_bson_init); run_test("/bson/init_static", test_bson_init_static); run_test("/bson/basic", test_bson_alloc); run_test("/bson/append_overflow", test_bson_append_overflow); run_test("/bson/append_array", test_bson_append_array); run_test("/bson/append_binary", test_bson_append_binary); run_test("/bson/append_binary_deprecated", test_bson_append_binary_deprecated); run_test("/bson/append_bool", test_bson_append_bool); run_test("/bson/append_code", test_bson_append_code); run_test("/bson/append_code_with_scope", test_bson_append_code_with_scope); run_test("/bson/append_dbpointer", test_bson_append_dbpointer); run_test("/bson/append_document", test_bson_append_document); run_test("/bson/append_double", test_bson_append_double); run_test("/bson/append_int32", test_bson_append_int32); run_test("/bson/append_int64", test_bson_append_int64); run_test("/bson/append_iter", test_bson_append_iter); run_test("/bson/append_maxkey", test_bson_append_maxkey); run_test("/bson/append_minkey", test_bson_append_minkey); run_test("/bson/append_null", test_bson_append_null); run_test("/bson/append_oid", test_bson_append_oid); run_test("/bson/append_regex", test_bson_append_regex); run_test("/bson/append_utf8", test_bson_append_utf8); run_test("/bson/append_symbol", test_bson_append_symbol); run_test("/bson/append_time_t", test_bson_append_time_t); run_test("/bson/append_timestamp", test_bson_append_timestamp); run_test("/bson/append_timeval", test_bson_append_timeval); run_test("/bson/append_undefined", test_bson_append_undefined); run_test("/bson/append_general", test_bson_append_general); run_test("/bson/append_deep", test_bson_append_deep); run_test("/bson/utf8_key", test_bson_utf8_key); run_test("/bson/validate", test_bson_validate); run_test("/bson/new_1mm", test_bson_new_1mm); run_test("/bson/init_1mm", test_bson_init_1mm); run_test("/bson/build_child", test_bson_build_child); run_test("/bson/build_child_deep", test_bson_build_child_deep); run_test("/bson/build_child_deep_no_begin_end", test_bson_build_child_deep_no_begin_end); run_test("/bson/build_child_array", test_bson_build_child_array); run_test("/bson/count", test_bson_count_keys); run_test("/bson/copy", test_bson_copy); run_test("/bson/copy_to", test_bson_copy_to); run_test("/bson/copy_to_excluding", test_bson_copy_to_excluding); run_test("/bson/initializer", test_bson_initializer); run_test("/bson/concat", test_bson_concat); return 0; }
int main(int argc, char *argv[]) { int nsites,d,i; if (!argv[1] || !argv[2]) exit(3); sscanf(argv[1], "%d", &nsites); sscanf(argv[2], "%d", &d); init_rand(0); while(nsites>0){ for (i=0;i<d;i++) printf("%6.0f ", floor(1e5*double_rand())); printf("\n"); nsites--; } }
bool init_ssl_internals () { if (!_bio_err) { SSL_library_init (); SSL_load_error_strings (); _bio_err = BIO_new_fp (stderr, BIO_NOCLOSE); } if (!init_rand ()) warn ("Failed to initialize random number generator in SSL\n"); return true; }
void damgard_jurik::key_gen(int modulusbits) { mpz_t p, q; gmp_randstate_t rand; mpz_init(pubkey->n); mpz_init(pubkey->g); mpz_init(prvkey->lambda); mpz_init(p); mpz_init(q); init_rand(rand, modulusbits / 8 + 1); do { do mpz_urandomb(p, rand, modulusbits / 2); while( !mpz_probab_prime_p(p, 10) ); do mpz_urandomb(q, rand, modulusbits / 2); while( !mpz_probab_prime_p(q, 10) ); /* compute the public modulus n = p q */ mpz_mul(pubkey->n, p, q); } while( !mpz_tstbit(pubkey->n, modulusbits - 1)); pubkey->bits = modulusbits; mpz_add_ui(pubkey->g, pubkey->n, 1); pubkey->n_j = new mpz_t[s_max + 2]; pubkey->k_n = new mpz_t[s_max + 2]; mpz_init(pubkey->n_j[0]); mpz_set_ui(pubkey->n_j[0], 1); mpz_init(pubkey->k_n[0]); mpz_set_ui(pubkey->k_n[0], 1); for (int i = 1;i <= s_max + 1;i++) { mpz_init(pubkey->n_j[i]); mpz_mul(pubkey->n_j[i], pubkey->n_j[i - 1], pubkey->n); mpz_init(pubkey->k_n[i]); mpz_mul_ui(pubkey->k_n[i], pubkey->k_n[i - 1], i); } /* Compute Private Key */ mpz_sub_ui(p, p, 1); mpz_sub_ui(q, q, 1); mpz_lcm(prvkey->lambda, p, q); mpz_clear(p); mpz_clear(q); gmp_randclear(rand); }
Agent * init(int * argc, char ** argv, int * myid, int * numprocs) { MPI_Init(argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, numprocs); MPI_Comm_rank(MPI_COMM_WORLD, myid); /* ローカルのエージェント数は、割り算で */ N_AGENTS = ALL_N_AGENTS / *numprocs; init_rand(myid); Agent * agents = malloc(sizeof(Agent) * N_AGENTS); init_agents(agents, N_AGENTS); return agents; }
int main() { init_rand(); SDL_Surface *ecran = NULL; SDL_Init(SDL_INIT_VIDEO); TTF_Init(); const SDL_VideoInfo *info_ecran = SDL_GetVideoInfo(); ecran = SDL_SetVideoMode(info_ecran->current_w, info_ecran->current_h, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN); SDL_FillRect(ecran, NULL, COULEUR_FOND); SDL_Flip(ecran); jeu(ecran); TTF_Quit(); SDL_Quit(); return 0; }
int main(int argc, char** argv) { // initialize randos init_rand(); // Create the UI impUI = new JetpackUI(); Fl::visual(FL_DOUBLE|FL_INDEX); impUI->show(); return Fl::run(); }
int main(void) { unsigned int i; init_rand(); for (i = 0; i < NUM_TIMERS; i++) { init_timer(&timers[i], expiry, NULL); schedule_timer(&timers[i], random() >> rand_shift); } count = NUM_TIMERS; while(count) { check_timers(false); stamp++; } return 0; }
/* * Routine: * Purpose: * Algorithm: * Data Structures: * * Params: * Returns: * Called By: * Calls: * Assumptions: * Side Effects: * TODO: None */ int main(int ac, char* av[]) { template_t *pTemplate; process_options (ac, av); if (!is_set("QUIET")) { fprintf (stderr, "%s Query Generator (Version %d.%d.%d%s)\n", get_str("PROG"), VERSION, RELEASE, MODIFICATION, PATCH); fprintf (stderr, "Copyright %s %s\n", COPYRIGHT, C_DATES); } TemplateList = makeList(L_FL_TAIL, NULL); /* sync the keyword defines between lex/yacc/qgen */ InitKeywords(); if (is_set("YYDEBUG")) yydebug = 1; if (is_set("TEMPLATE")) parseTemplate(get_str("TEMPLATE"), 1); else parseQueries(); /* load the query templates */ if (is_set("VERBOSE") && !is_set("QUIET")) fprintf(stderr, "Parsed %d templates\n", length(TemplateList)); if (is_set("DUMP")) { for (pTemplate = (template_t *)getHead(TemplateList); pTemplate; pTemplate = (template_t *)getNext(TemplateList)) PrintTemplate(pTemplate); } init_rand(); generateQueryStreams(); /* output the resulting SQL */ exit(0); }
double Alea() { u32 Kx[NK]; // pour l'AES u32 Kex[NB*NR]; // pour l'AES u32 Px[NB]; // pour l'AES srand(time(NULL)); //INIT RAND int tmp =rand(); // Initialisation de la clé et du plaintext pour l'AES // 45 est un paramètre qui doit changer à chaque initialisation init_rand(Kx, Px, NK, NB, tmp); // construction des sous-clés pour l'AES //KeyExpansion(Kex,Kx); // Generation d'un nombre aléatoire avec AES (sortie sur 32 bits) word32 result = AES(Px, Kex); return (result/(double) UINT_MAX); }
int main(int cn, char **cl) { unsigned BER, PoB, model; if (cn < 5) { puts("usage: eg <sd> <rd> <st> <model> [BER] [PoB]"); puts(" <sd> tcpdump sender"); puts(" <rd> tcpdump receiver (will be generated)"); puts(" <st> tracefile sender"); puts(" <model> AWGN or GE"); puts(" [BER] reciprocal Bit Error Rate (1000 -> 0.001)"); puts(" [PoB] Play-out buffer [ms]"); return 0; } BER = (cn > 5) ? strtoul(cl[5], 0, 10) : 0; if (BER < 10 || BER > 10000000) { BER = 10000; fprintf(stderr, "BER set to %g.\n", 1. / BER); } if (!strcmp(cl[4], "AWGN")) model = 0; else if (!strcmp(cl[4], "GE")) model = 1; else { fprintf(stderr, "unknown error model"); return EXIT_FAILURE; } PoB = (cn > 6) ? strtoul(cl[6], 0, 10) : 0; if (PoB < 10 || PoB > 10000) { PoB = 250; fprintf(stderr, "Play-out buffer set to %u ms.\n", PoB); } init_rand(); if (!ReadDump(cl, &D, 2, 0)) return EXIT_FAILURE; if (!GenRD_Std(cl[2], D.P, D.nP, model, BER, PoB)) return EXIT_FAILURE; free(D.P); free(D.F); return 0; }
unsigned int next_rand(void) { init_rand(); if(s_pRtlGenRandom) { unsigned int rnd; if(s_pRtlGenRandom(&rnd, sizeof(unsigned int))) { return rnd; } } const unsigned int x = my_rand(); const unsigned int y = my_rand(); const unsigned int z = my_rand(); return mix_function(x, y, z); }