这篇教程C++ srandomdev函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中srandomdev函数的典型用法代码示例。如果您正苦于以下问题:C++ srandomdev函数的具体用法?C++ srandomdev怎么用?C++ srandomdev使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了srandomdev函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: mgt_cli_secretvoidmgt_cli_secret(const char *S_arg){ int i, fd; char buf[BUFSIZ]; /* Save in shmem */ mgt_SHM_static_alloc(S_arg, strlen(S_arg) + 1L, "Arg", "-S", ""); srandomdev(); /* XXX: why here ??? */ fd = open(S_arg, O_RDONLY); if (fd < 0) { fprintf(stderr, "Can not open secret-file /"%s/"/n", S_arg); exit (2); } mgt_got_fd(fd); i = read(fd, buf, sizeof buf); if (i == 0) { fprintf(stderr, "Empty secret-file /"%s/"/n", S_arg); exit (2); } if (i < 0) { fprintf(stderr, "Can not read secret-file /"%s/"/n", S_arg); exit (2); } AZ(close(fd)); secret_file = S_arg;}
开发者ID:mavenik,项目名称:Varnish-Cache,代码行数:28,
示例2: getargint ROKEN_LIB_FUNCTIONgetarg(struct getargs *args, size_t num_args, int argc, char **argv, int *goptind){ int i; int ret = 0;#if defined(HAVE_SRANDOMDEV) srandomdev();#elif defined(HAVE_RANDOM) srandom(time(NULL));#else srand (time(NULL));#endif (*goptind)++; for(i = *goptind; i < argc; i++) { if(argv[i][0] != '-') break; if(argv[i][1] == '-'){ if(argv[i][2] == 0){ i++; break; } ret = arg_match_long (args, num_args, argv[i] + 2, argc, argv, &i); } else { ret = arg_match_short (args, num_args, argv[i], argc, argv, &i); } if(ret) break; } *goptind = i; return ret;}
开发者ID:0x24bin,项目名称:winexe-1,代码行数:35,
示例3: mainint main( int argc, char ** argv ){ int iterations = 10000; int i = 0; simple_metrics* sm = simple_metrics_new(); if ( argc > 1 ) { iterations = atol( argv[1] ); } printf("Running for %d iterations/n", iterations ); srandomdev(); for( i = 0 ; i < iterations ; i++ ) { double d = (double)random(); simple_metrics_update( sm, d ); }; printf( "Count : %ld/n" , simple_metrics_count( sm ) ); printf( "Min : %0.5lf/n", simple_metrics_min( sm ) ); printf( "Max : %0.5lf/n", simple_metrics_max( sm ) ); printf( "Sum : %0.5lf/n", simple_metrics_sum( sm ) ); printf( "Mean : %0.5lf/n", simple_metrics_mean( sm ) ); printf( "Rate : %0.5lf/n", simple_metrics_rate( sm ) ); printf( "Stddev : %0.5lf/n", simple_metrics_stddev( sm ) ); simple_metrics_free( sm ); return 0;}
开发者ID:copiousfreetime,项目名称:libsimple_metrics,代码行数:32,
示例4: tac_open/* * Create and initialize a tac_handle structure, and return it to the * caller. Can fail only if the necessary memory cannot be allocated. * In that case, it returns NULL. */struct tac_handle *tac_open(void){ int i; struct tac_handle *h; h = (struct tac_handle *)malloc(sizeof(struct tac_handle)); if (h != NULL) { h->fd = -1; h->num_servers = 0; h->cur_server = 0; h->errmsg[0] = '/0'; init_clnt_str(&h->user); init_clnt_str(&h->port); init_clnt_str(&h->rem_addr); init_clnt_str(&h->data); init_clnt_str(&h->user_msg); for (i=0; i<MAXAVPAIRS; i++) { init_clnt_str(&(h->avs[i])); init_srvr_str(&(h->srvr_avs[i])); } init_srvr_str(&h->srvr_msg); init_srvr_str(&h->srvr_data); srandomdev(); } return h;}
开发者ID:alexandermerritt,项目名称:dragonfly,代码行数:32,
示例5: mainint main (int argc, char* argv[]) { /* This holds the current line */ string_chunk* current = new_chunk_string(); /* This is my array of output registers */ string_chunk** values = NULL; /* This is the number of random values we've been asked for */ long requested = 1; /* This is the number of lines we've read thus far. */ int number = 0; /* This is just a counter for the for loops. */ long i; if (argc > 1) { char* end; requested = strtol(argv[1], &end, 10); if (end == argv[1]) { /* Invalid Number */ fputs("Only Argument Must Be A Number/n", stderr); exit(1); } else if (requested <= 0) { fputs("Number Must Be A Positive Integer/n", stderr); exit(1); } } /* Allocate All My Value Registers */ values = malloc(sizeof(string_chunk*) * requested); /* And Initialize them to empty strings */ for(i = 0; i < requested; i++) { values[i] = new_chunk_string(); } #ifdef S_RAND_DEV /* I like srandomdev better, but it's only on BSD */ srandomdev(); #else srandom(time(NULL)); #endif while (!feof(stdin)) { if (chunk_readline(stdin, current) > 0) { /* Not a blank line */ number++; for (i = 0; i < requested; i++) { /* Now we make a random number between 1 and number. If it's 1, we copy the current line to the current register. Otherwise, we leave it as it is. */ /* This should, as number increases, guarantee that by the end, all lines will have had equal 1/n chance of making it to the end. */ if (randBetween(1,number) == 1) { /* We should now copy current to the value register */ chunk_string_copy(current, values[i]); } } } } for (i = 0; i < requested; i++) { chunk_printline(stdout, values[i]); putc('/n', stdout); } return 0;}
开发者ID:psycotica0,项目名称:Pick,代码行数:60,
示例6: mainint main(void){ t_class *c = class_new("o.O", (method)oO_new, (method)oO_free, sizeof(t_oO), 0L, A_GIMME, 0); //class_addmethod(c, (method)oO_fullPacket, "FullPacket", A_LONG, A_LONG, 0); class_addmethod(c, (method)oO_fullPacket, "FullPacket", A_GIMME, 0); class_addmethod(c, (method)oO_assist, "assist", A_CANT, 0); class_addmethod(c, (method)oO_doc, "doc", 0); //class_addmethod(c, (method)oO_bang, "bang", 0); //class_addmethod(c, (method)oO_anything, "anything", A_GIMME, 0); // remove this if statement when we stop supporting Max 5 //if(omax_dict_resolveDictStubs()){ class_addmethod(c, (method)omax_dict_dictionary, "dictionary", A_GIMME, 0); //} class_addmethod(c, (method)odot_version, "version", 0); class_register(CLASS_BOX, c); oO_class = c; common_symbols_init(); ODOT_PRINT_VERSION; srandomdev(); return 0;}
开发者ID:CNMAT,项目名称:CNMAT-odot,代码行数:25,
示例7: mainint main (int argc, char *argv[]){ int num_environment_files, next_env_file; struct dirent **environment_files;#ifdef __linux__ srandom ((int) time (NULL));#else srandomdev ();#endif if (! get_env_filenames (&environment_files, &num_environment_files)) return 1; if (! create_result_directory ()) return 1; if (! initialize_all_agents ()) return 1; for (next_env_file = 0; next_env_file < num_environment_files; next_env_file++) { run_one_simulation (environment_files[next_env_file]); } release_all_agents (); return 0;}
开发者ID:gusboling,项目名称:AgentWorld,代码行数:29,
示例8: randomize/* * randomize: * Randomize the order of the string table. We must be careful * not to randomize across delimiter boundaries. All * randomization is done within each block. */voidrandomize(void){ uint32_t cnt, i; off_t tmp; off_t *sp;#if __FreeBSD_version < 800041 srandomdev();#endif Tbl.str_flags |= STR_RANDOM; cnt = Tbl.str_numstr; /* * move things around randomly */ for (sp = Seekpts; cnt > 0; cnt--, sp++) {#if __FreeBSD_version < 800041 i = random() % cnt;#else i = arc4random_uniform(cnt);#endif tmp = sp[0]; sp[0] = sp[i]; sp[i] = tmp; }}
开发者ID:coyizumi,项目名称:cs111,代码行数:35,
示例9: mgt_cli_secretvoidmgt_cli_secret(const char *S_arg){ int i, fd; char buf[BUFSIZ]; char *p; /* Save in shmem */ i = strlen(S_arg); p = VSM_Alloc(i + 1, "Arg", "-S", ""); AN(p); strcpy(p, S_arg); srandomdev(); fd = open(S_arg, O_RDONLY); if (fd < 0) { fprintf(stderr, "Can not open secret-file /"%s/"/n", S_arg); exit (2); } mgt_got_fd(fd); i = read(fd, buf, sizeof buf); if (i == 0) { fprintf(stderr, "Empty secret-file /"%s/"/n", S_arg); exit (2); } if (i < 0) { fprintf(stderr, "Can not read secret-file /"%s/"/n", S_arg); exit (2); } AZ(close(fd)); secret_file = S_arg;}
开发者ID:BabyOnlineSG,项目名称:pkg-varnish,代码行数:32,
示例10: CreateInterfaceIDvoidCreateInterfaceID(u_char *intid, int r){ struct sockaddr_dl hwaddr; u_char *ether; if (!r) { if (!GetEther(NULL, &hwaddr)) { ether = (u_char *)LLADDR(&hwaddr); intid[0] = ether[0] ^ 0x02; /* reverse the u/l bit */ intid[1] = ether[1]; intid[2] = ether[2]; intid[3] = 0xff; intid[4] = 0xfe; intid[5] = ether[3]; intid[6] = ether[4]; intid[7] = ether[5]; return; } } srandomdev(); ((u_int32_t *)intid)[0] = (((u_int32_t)random()) % 0xFFFFFFFF) + 1; ((u_int32_t *)intid)[1] = (((u_int32_t)random()) % 0xFFFFFFFF) + 1; intid[0] &= 0xfd;}
开发者ID:vstakhov,项目名称:mpd,代码行数:26,
示例11: CNT_InitvoidCNT_Init(void){ srandomdev(); xids = random(); CLI_AddFuncs(DEBUG_CLI, debug_cmds);}
开发者ID:akrito,项目名称:Varnish-Least-Busy-Director,代码行数:8,
示例12: defined//// Constructor//FnRandom::FnRandom(){#if defined(__FreeBSD__) || defined(_MSC_VER) srandomdev();#else srandom(time(NULL));#endif}
开发者ID:Azq2,项目名称:ctpp2,代码行数:11,
示例13: CNT_InitvoidCNT_Init(void){ srandomdev(); srand48(random()); xids = random(); CLI_AddFuncs(debug_cmds);}
开发者ID:iamnafets,项目名称:Varnish-Cache,代码行数:9,
示例14: startupvoidstartup(void){ demo = Start(); srandomdev(); hinted[3] = yes(65, 1, 0); newloc = 1; delhit = 0; limit = 330; if (hinted[3]) limit = 1000; /* better batteries if instrucs */}
开发者ID:AhmadTux,项目名称:DragonFlyBSD,代码行数:12,
示例15: parse_optsvoid parse_opts(int argc, char **argv) { static struct option longopts[] = { { "seed", required_argument, 0, 's' }, { "csv", no_argument, 0, 'c' }, { "tab", no_argument, 0, 't' }, { "delimiters", required_argument, 0, 'd' }, { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 } }; int c; while ((c = getopt_long(argc,argv,"s:ctd:h",longopts,0)) != -1) { switch (c) { case 's': seed = atol(optarg); break; case 'c': delimiters = comma; break; case 't': delimiters = tab; break; case 'd': delimiters = optarg ? optarg : defsep; // TODO: ensure that /n is included!!! break; case 'h': printf("%s",usage); exit(0); case '?': if (isprint(optopt)) die("Unknown option `-%c'./n",optopt); else die("Strange option `//x%x'./n",optopt); default: die("ERROR: getopt badness./n"); } } if (!delimiters) delimiters = defsep; if (!seed) { srandomdev(); seed = random(); } srand48(seed);}
开发者ID:StefanKarpinski,项目名称:trace_tools,代码行数:52,
示例16: mainint main(void) { int vector[VECTOR_LENGTH], element; for (element = 0; element < VECTOR_LENGTH; ++element) { srandomdev(); vector[element] = random() % 10; } quick_sort(vector, 0, VECTOR_LENGTH - 1); print_vector(vector); return 0;}
开发者ID:DeadDork,项目名称:learning_c,代码行数:13,
示例17: playlist_initvoidplaylist_init(void){#ifdef HAVE_RANDOM# ifdef HAVE_SRANDOMDEV srandomdev();# else srandom((unsigned int)time(NULL));# endif /* HAVE_SRANDOMDEV */#else srand((unsigned int)time(NULL));#endif /* HAVE_RANDOM */}
开发者ID:DragonZX,项目名称:ezstream-ext,代码行数:13,
示例18: rk_random_initvoid ROKEN_LIB_FUNCTIONrk_random_init(void){#if defined(HAVE_ARC4RANDOM) arc4random_stir();#elif defined(HAVE_SRANDOMDEV) srandomdev();#elif defined(HAVE_RANDOM) srandom(time(NULL));#else srand (time(NULL));#endif}
开发者ID:2asoft,项目名称:freebsd,代码行数:13,
示例19: defined void Security::init() { if( _initialized ) return; _initialized = true; #if defined(__linux__) || defined(__sunos__) _devrandom = new std::ifstream("/dev/urandom", std::ios::binary|std::ios::in); assert(_devrandom->is_open() && "can't open dev/urandom"); #elif defined(_WIN32) srand(time(NULL)); #else srandomdev(); #endif }
开发者ID:LeviSchuck,项目名称:cordite-libs,代码行数:13,
示例20: init_srandomvoid init_srandom(void){#ifdef HAVE_SRANDOMDEV srandomdev();#else /* this piece of code comes from srandomdev() source */ struct timeval tv; unsigned long junk; /* XXX left uninitialized on purpose */ gettimeofday(&tv, NULL); srandom(getpid() ^ tv.tv_sec ^ tv.tv_usec ^ junk);#endif}
开发者ID:xiu,项目名称:child,代码行数:13,
示例21: srandom_initvoid srandom_init(void){ #ifndef WIN32 #ifdef __OpenBSD__ srandomdev(); #else unsigned int seed; randombytes(&seed, sizeof seed); srandom(seed); #endif // __OpenBSD__ #endif // Win32}
开发者ID:ariosx,项目名称:ossec-hids,代码行数:14,
示例22: init_zrandstatic void init_zrand(void){ struct timeval tv; struct timezone tz; gettimeofday(&tv, &tz);#ifdef HAVE_SRANDOMDEV srandomdev();#elif defined(HAVE_RANDOM) srandom((unsigned int) (tv.tv_sec ^ tv.tv_usec ^ (getpid() << 16)));#else srand((unsigned int) (tv.tv_sec ^ tv.tv_usec ^ (getpid() << 16)));#endif}
开发者ID:jhoblitt,项目名称:pure-ftpd-old,代码行数:14,
示例23: randinitvoidrandinit(void){#if defined(__DragonFly__) static int initdone; /* srandomdev() call is only required once */ if (!initdone) { initdone = 1; srandomdev(); }#else srandom((time(NULL)^getpid())+random());#endif}
开发者ID:Gwenio,项目名称:DragonFlyBSD,代码行数:14,
示例24: mainintmain(int argc, char *argv[]){ int ch, move; while ((ch = getopt(argc, argv, "ph")) != -1) switch(ch) { case 'p': promode = 1; break; case '?': case 'h': default: usage(); } srandomdev(); instructions(); init(); if (nrandom(2) == 1) { printplayer(COMPUTER); (void)printf("get to start./n"); goto istart; } printplayer(USER); (void)printf("get to start./n"); for (;;) { move = usermove(); if (!comphand[move]) { if (gofish(move, USER, userhand)) continue; } else { goodmove(USER, move, userhand, comphand); continue; }istart: for (;;) { move = compmove(); if (!userhand[move]) { if (!gofish(move, COMPUTER, comphand)) break; } else goodmove(COMPUTER, move, comphand, userhand); } } /* NOTREACHED */}
开发者ID:jyin0813,项目名称:OpenBSD-src,代码行数:49,
示例25: mainintmain(int argc, char *argv[]){ pthread_t producers[PRODUCER_THREADS]; pthread_t consumers[CONSUMER_THREADS]; int i; int ids[PRODUCER_THREADS + CONSUMER_THREADS]; (void)argc; (void)argv; srandomdev(); printf("Init queue.../n"); q = queue_init(); queue_limit(q, 5); printf("Done, queue allocated at %p, starting workers/n", (void *)q); for (i=0; i < PRODUCER_THREADS; i++) { ids[i] = i; AZ(pthread_create(&producers[i], NULL, produce, &ids[i])); } for (i = 0; i < CONSUMER_THREADS; i++) { ids[i] = i; AZ(pthread_create(&consumers[i], NULL, consume, &ids[i])); } for (i=0;i < PRODUCER_THREADS;i++) if (producers[i]) pthread_join(producers[i], NULL); for (i=0;i < CONSUMER_THREADS;i++) if (consumers[i]) queue_enq(q, NULL); for (i=0;i < CONSUMER_THREADS;i++) if (consumers[i]) pthread_join(consumers[i], NULL); printf("Ok, still alive. Now see if destroy works.../n"); queue_destroy(q); printf("Still here. Time to go./n"); return 0;}
开发者ID:c-ong,项目名称:libshcodecs,代码行数:47,
示例26: defined void Security::init() { if( _initialized ) return; _initialized = true;#if defined(__linux__) || defined(__sunos__) _devrandom = new ifstream("/dev/urandom", ios::binary|ios::in); massert( 10353 , "can't open dev/urandom", _devrandom->is_open() );#elif defined(_WIN32) srand(curTimeMicros());#else srandomdev();#endif#ifndef NDEBUG if ( do_md5_test() ) massert( 10354 , "md5 unit test fails", false);#endif }
开发者ID:BendustiK,项目名称:mongo,代码行数:18,
示例27: mainint main(void){ unsigned char *compressed; size_t compressed_size; char *uncompressed; size_t uncompressed_size;#ifndef __linux__ srandomdev();#endif dicky_compress(&compressed, &compressed_size, STR, strlen(STR)); dicky_uncompress(&uncompressed, &uncompressed_size, compressed, compressed_size); dicky_free(compressed); dicky_free(uncompressed); return 0;}
开发者ID:carriercomm,项目名称:Dicky,代码行数:18,
示例28: defined NOINLINE_DECL void Security::init() { if( _initialized ) return; _initialized = true;#if defined(__linux__) || defined(__sunos__) || defined(__APPLE__) _devrandom = new ifstream("/dev/urandom", ios::binary|ios::in); massert( 10353 , "can't open dev/urandom", _devrandom->is_open() );#elif defined(_WIN32) srand(curTimeMicros()); // perhaps not relevant for rand_s but we might want elsewhere anyway#else srandomdev();#endif#ifndef NDEBUG if ( do_md5_test() ) massert( 10354 , "md5 unit test fails", false);#endif }
开发者ID:RyokoAkizuki,项目名称:freshcity,代码行数:18,
示例29: oc_newstatic void oc_new(char *dst) { int have_hash = 0, i; unsigned char hash[21];#ifdef HAVE_TLS if (RAND_bytes(hash, 21) || RAND_pseudo_bytes(hash, 21)) have_hash = 1;#endif if (!have_hash) { /* should only be used if TLS is not available or it fails */ unsigned char rbuf[64]; if (!rand_inited) {#ifdef HAVE_SRANDOMDEV srandomdev();#else#ifdef Win32 srand(time(NULL) ^ (getpid() << 12));#else /* fall back -- mix of time and pid is the best we can do ... */ srandom(time(NULL) ^ (getpid() << 12));#endif#endif rand_inited = 1; } #ifdef Win32 for (i = 0; i < sizeof(rbuf); i++) rbuf[i] = rand();#else for (i = 0; i < sizeof(rbuf); i++) rbuf[i] = random();#endif /* we use random -> SHA1 .. is it an overkill? */ sha1hash((const char*)rbuf, sizeof(rbuf) - 1, hash); /* the last byte is the hold-out byte -- just because SHA gives only 160 bits */ hash[20] = rbuf[sizeof(rbuf) - 1]; } if (Rserve_oc_prefix) *(dst++) = Rserve_oc_prefix; for (i = 0; i < 21; i += 3) { *(dst++) = b64map[hash[i] & 63]; *(dst++) = b64map[((hash[i] >> 6) | (hash[i + 1] << 2)) & 63]; *(dst++) = b64map[((hash[i + 1] >> 4) | (hash[i + 2] << 4)) & 63]; *(dst++) = b64map[hash[i + 2] >> 2]; } *dst = 0;}
开发者ID:JanWielemaker,项目名称:Rserve,代码行数:44,
示例30: mainintmain(int argc, char *argv[]){ int n, ex = 0; struct rlimit rl; while ((n = getopt(argc, argv, "bfp")) != -1) { switch (n) { case 'b': ignorelabel++; break; case 'p': printonly++; break; case 'f': force++; break; default: usage(); } } if (argc - optind < 1) usage(); srandomdev(); /* Increase our data size to the max */ if (getrlimit(RLIMIT_DATA, &rl) == 0) { rl.rlim_cur = rl.rlim_max; if (setrlimit(RLIMIT_DATA, &rl) < 0) warn("can't get resource limit to max data size"); } else warn("can't get resource limit for data size"); for (n = optind; n < argc; n++) { if (argc - optind != 1) (void)puts(argv[n]); ex += fsirand(argv[n]); if (n < argc - 1) putchar('/n'); } exit(ex);}
开发者ID:2trill2spill,项目名称:freebsd,代码行数:44,
注:本文中的srandomdev函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ src函数代码示例 C++ srandom函数代码示例 |