예제 #1
0
void
mgt_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;
}
예제 #2
0
파일: getarg.c 프로젝트: 0x24bin/winexe-1
int ROKEN_LIB_FUNCTION
getarg(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;
}
예제 #3
0
int 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;
}
예제 #4
0
/*
 * 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;
}
예제 #5
0
파일: pick.c 프로젝트: psycotica0/Pick
int 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;
}
예제 #6
0
파일: o.O.c 프로젝트: CNMAT/CNMAT-odot
int 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;
}
예제 #7
0
파일: main.c 프로젝트: gusboling/AgentWorld
int 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;
}
예제 #8
0
파일: strfile.c 프로젝트: coyizumi/cs111
/*
 * 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.
 */
void
randomize(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;
	}
}
예제 #9
0
void
mgt_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;
}
예제 #10
0
파일: ipv6cp.c 프로젝트: vstakhov/mpd
void
CreateInterfaceID(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;

}
void
CNT_Init(void)
{

    srandomdev();
    xids = random();
    CLI_AddFuncs(DEBUG_CLI, debug_cmds);
}
예제 #12
0
파일: FnRandom.cpp 프로젝트: Azq2/ctpp2
//
// Constructor
//
FnRandom::FnRandom()
{
#if defined(__FreeBSD__) || defined(_MSC_VER)
	srandomdev();
#else
	srandom(time(NULL));
#endif
}
예제 #13
0
void
CNT_Init(void)
{

    srandomdev();
    srand48(random());
    xids = random();
    CLI_AddFuncs(debug_cmds);
}
예제 #14
0
void
startup(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 */
}
예제 #15
0
void 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);
}
예제 #16
0
int 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;
}
예제 #17
0
void
playlist_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 */
}
예제 #18
0
파일: rand.c 프로젝트: 2asoft/freebsd
void ROKEN_LIB_FUNCTION
rk_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
}
예제 #19
0
    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
    }
예제 #20
0
파일: child.c 프로젝트: xiu/child
void 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
}
예제 #21
0
void srandom_init(void)
{

    #ifndef WIN32
    #ifdef __OpenBSD__
    srandomdev();
    #else
    unsigned int seed;
    randombytes(&seed, sizeof seed);
    srandom(seed);
    #endif  // __OpenBSD__
    #endif  // Win32

}
예제 #22
0
static 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
}
예제 #23
0
파일: defs.c 프로젝트: Gwenio/DragonFlyBSD
void
randinit(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
}
예제 #24
0
파일: fish.c 프로젝트: jyin0813/OpenBSD-src
int
main(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 */
}
예제 #25
0
int
main(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;
}
예제 #26
0
파일: nonce.cpp 프로젝트: BendustiK/mongo
    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
    }
예제 #27
0
파일: test.c 프로젝트: carriercomm/Dicky
int 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;
}
예제 #28
0
    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
    }
예제 #29
0
파일: oc.c 프로젝트: JanWielemaker/Rserve
static 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;
}
예제 #30
0
int
main(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);
}