您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ srandom函数代码示例

51自学网 2021-06-03 08:16:54
  C++
这篇教程C++ srandom函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中srandom函数的典型用法代码示例。如果您正苦于以下问题:C++ srandom函数的具体用法?C++ srandom怎么用?C++ srandom使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了srandom函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

//.........这里部分代码省略.........   *  as possible.  So we'll farm them out among SeekProcCount processes.   *  We'll control them by writing 1-byte tickets down a pipe which   *  the children all read.  We write "Seeks" bytes with val 1, whichever   *  child happens to get them does it and the right number of seeks get   *  done.   * The idea is that since the write() of the tickets is probably   *  atomic, the parent process likely won't get scheduled while the   *  children are seeking away.  If you draw a picture of the likely   *  timelines for three children, it seems likely that the seeks will   *  overlap very nicely with the process scheduling with the effect   *  that there will *always* be a seek() outstanding on the file.   * Question: should the file be opened *before* the fork, so that   *  all the children are lseeking on the same underlying file object?   */  if (pipe(seek_feedback) == -1 || pipe(seek_control) == -1)    io_error("pipe");  for (next = 0; next < Seeks; next++)    seek_tickets[next] = 1;  for ( ; next < (Seeks + SeekProcCount); next++)    seek_tickets[next] = 0;  /* launch some parallel seek processes */  for (next = 0; next < SeekProcCount; next++)  { /* for each seek proc */    if ((child = fork()) == -1)      io_error("fork");    else if (child == 0)    { /* child process */      /* set up and wait for the go-ahead */      close(seek_feedback[0]);      close(seek_control[1]);      newfile(name, &fd, &stream, 0);      srandom(getpid());      fprintf(stderr, "Seeker %d...", next + 1);      /* wait for the go-ahead */      if (read(seek_control[0], seek_tickets, 1) != 1)	io_error("read ticket");      timestamp();      seeker_report[StartTime] = time_so_far();      /* loop until we read a 0 ticket back from our parent */      while(seek_tickets[0])      { /* until Mom says stop */        doseek((long) (random() % (size / Chunk)), fd,	  ((lseek_count++ % UpdateSeek) == 0));	if (read(seek_control[0], seek_tickets, 1) != 1)	  io_error("read ticket");      } /* until Mom says stop */      if (close(fd) == -1)        io_error("close after seek");      /* report to parent */      get_delta_t(Lseek);      seeker_report[EndTime] = time_so_far();      seeker_report[CPU] = delta[(int) Lseek][CPU];      if (write(seek_feedback[1], seeker_report, sizeof(seeker_report))          != sizeof(seeker_report))        io_error("pipe write");      exit(0);    } /* child process */  } /* for each seek proc */  /*   * Back in the parent; in an effort to ensure the children get an even
开发者ID:Fantasticer,项目名称:llamaOS,代码行数:67,


示例2: srandom

/*------------------------------------------------------------------- * Function:    Thread_work * Purpose:     Run BARRIER_COUNT barriers * In arg:      rank * Global var:  barrier * Return val:  Ignored */void *Thread_work(void* rank) {  long my_rank = (long) rank;  int i, j, seed, index, offset, local_chunk_size, local_sample_size;  int local_pointer, s_index, my_segment, col_sum;  int *local_data;  local_chunk_size = list_size / thread_count;  local_sample_size = sample_size / thread_count;    // printf("Hi this is thread %ld, I have %d chunks and should do %d samples. /n", my_rank, local_chunk_size, local_sample_size);    // Get sample keys randomly from original list  srandom(my_rank + 1);    offset = my_rank * local_sample_size;    for (i = offset; i < (offset + local_sample_size); i++) {	  do {		  // If while returns 1, you'll be repeating this		  seed = (my_rank * local_chunk_size) + (random() % local_chunk_size);	  } while (Is_used(seed, offset, local_sample_size));	  // If the loop breaks (while returns 0), data is clean, assignment	  sample_keys[i] = list[seed];	  index = offset + i;	  	  // printf("T%ld, seed = %d/n", my_rank, seed);	  // printf("T%ld, index = %d, i = %d, key = %d, LCS = %d/n/n", my_rank, index, i, list[seed], local_sample_size);  }    // Ensure all threads have reached this point, and then let continue  pthread_barrier_wait(&barrier);    // Parallel count sort the sample keys  for (i = offset; i < (offset + local_sample_size); i++) {	  int mykey = sample_keys[i];	  int myindex = 0;	  for (j = 0; j < sample_size; j++) {		  if (sample_keys[j] < mykey) {			  myindex++;		  } else if (sample_keys[j] == mykey && j < i) {			  myindex++;		  } else {		  }	  }	  // printf("##### P%ld Got in FINAL, index = %d, mykey = %d, myindex = %d/n", my_rank, i, mykey, myindex);	  sorted_keys[myindex] = mykey;  }    // Ensure all threads have reached this point, and then let continue  pthread_barrier_wait(&barrier);    // Besides thread 0, every thread generates a splitter  // splitters[0] should always be zero  if (my_rank != 0) {	  splitters[my_rank] = (sorted_keys[offset] + sorted_keys[offset-1]) / 2;  }    // Ensure all threads have reached this point, and then let continue  pthread_barrier_wait(&barrier);  // Using block partition to retrieve and sort local chunk  local_pointer = my_rank * local_chunk_size;  local_data = malloc(local_chunk_size * sizeof(int));  j = 0;  for (i = local_pointer; i < (local_pointer + local_chunk_size); i++) {  	  local_data[j] = list[i];	  j++;  }    // Quick sort on local data before splitting into buckets  qsort(local_data, local_chunk_size, sizeof(int), Int_comp);    // index in the splitter array  s_index = 1;	  // starting point of this thread's segment in dist arrays  my_segment = my_rank * thread_count;     // Generate the original distribution array, loop through each local entry  for (i = 0; i < local_chunk_size; i++) {	  if (local_data[i] < splitters[s_index]) {		  // If current elem lesser than current splitter		  // That means it's within this bucket's range, keep looping	  } else {		  // Elem is out of bucket's range, time to increase splitter		  // Keep increasing until you find one that fits		  // Also make sure if equals we still increment		  while (s_index < thread_count && local_data[i] >= splitters[s_index]) {			  s_index++;		  }	  }	  // Add to the raw distribution array, -1 because splitter[0] = 0	  raw_dist[my_segment + s_index-1]++;  }//.........这里部分代码省略.........
开发者ID:karuto,项目名称:Parallel-Sample-Sort,代码行数:101,


示例3: main

int main(int ac, char **av){	int i = 1;	const char *name;	struct stat tmpstat;	if (ac > i && av[i][0] == '-') {		switch (av[i++][1]) {		case 'o':			input_mode = ask_new;			break;		case 's':			input_mode = ask_silent;			valid_stdin = isatty(0) && isatty(1) && isatty(2);			break;		case 'd':			input_mode = set_default;			break;		case 'D':			input_mode = set_default;			defconfig_file = av[i++];			if (!defconfig_file) {				printf("%s: No default config file specified/n",					av[0]);				exit(1);			}			break;		case 'n':			input_mode = set_no;			break;		case 'm':			input_mode = set_mod;			break;		case 'y':			input_mode = set_yes;			break;		case 'r':			input_mode = set_random;			srandom(time(NULL));			break;		case 'h':		case '?':			printf("%s [-o|-s] config/n", av[0]);			exit(0);		}	}  	name = av[i];	if (!name) {		printf("%s: configuration file missing/n", av[0]);	}	conf_parse(name);	//zconfdump(stdout);	switch (input_mode) {	case set_default:		if (!defconfig_file)			/* Freetz: We don't have .defconfig file, create config from defaults */			/* defconfig_file = conf_get_default_confname(); */			break;	case ask_silent:		if (stat(".config", &tmpstat)) {			printf("***/n"				"*** You have not yet configured Freetz!/n"				"***/n"				"*** Please run some configurator (e.g. /"make oldconfig/" or/n"				"*** /"make menuconfig/" or /"make config/")./n"				"***/n");			exit(1);		}	case ask_all:	case ask_new:		conf_read(NULL);		break;	default:		break;	}	if (input_mode != ask_silent) {		rootEntry = &rootmenu;		conf(&rootmenu);		if (input_mode == ask_all) {			input_mode = ask_silent;			valid_stdin = 1;		}	}	do {		conf_cnt = 0;		check_conf(&rootmenu);	} while (conf_cnt);	if (conf_write(NULL)) {		fprintf(stderr, "/n*** Error during writing of the Freetz configuration./n/n");		return 1;	}	return 0;}
开发者ID:carriercomm,项目名称:freetz,代码行数:94,


示例4: main

int main() {  int status = 0;  srandom(17);  status += test_pluq_structured(37, 37);  status += test_pluq_structured(63, 63);  status += test_pluq_structured(64, 64);  status += test_pluq_structured(65, 65);  status += test_pluq_structured(128, 128);  status += test_pluq_structured(37, 137);  status += test_pluq_structured(65, 5);  status += test_pluq_structured(128, 18);  status += test_pluq_full_rank(13, 13);  status += test_pluq_full_rank(37, 37);  status += test_pluq_full_rank(63, 63);  status += test_pluq_full_rank(64, 64);  status += test_pluq_full_rank(65, 65);  status += test_pluq_full_rank(97, 97);   status += test_pluq_full_rank(128, 128);  status += test_pluq_full_rank(150, 150);  status += test_pluq_full_rank(256, 256);  status += test_pluq_full_rank(1024, 1024);  status += test_pluq_full_rank(13, 11);  status += test_pluq_full_rank(37, 39);  status += test_pluq_full_rank(64, 164);  status += test_pluq_full_rank(97, 92);  status += test_pluq_full_rank(128, 121);  status += test_pluq_full_rank(150, 153);  status += test_pluq_full_rank(256, 258);  status += test_pluq_full_rank(1024, 1023);  status += test_pluq_half_rank(64, 64);  status += test_pluq_half_rank(65, 65);  status += test_pluq_half_rank(66, 66);  status += test_pluq_half_rank(127, 127);  status += test_pluq_half_rank(129, 129);  status += test_pluq_half_rank(148, 148);  status += test_pluq_half_rank(132, 132);  status += test_pluq_half_rank(256, 256);  status += test_pluq_half_rank(1024, 1024);  status += test_pluq_half_rank(129, 127);  status += test_pluq_half_rank(132, 136);  status += test_pluq_half_rank(256, 251);  status += test_pluq_half_rank(1024, 2100);  status += test_pluq_random(63, 63);  status += test_pluq_random(64, 64);  status += test_pluq_random(65, 65);  status += test_pluq_random(128, 128);  status += test_pluq_random(128, 131);  status += test_pluq_random(132, 731);  status += test_pluq_random(150, 150);  status += test_pluq_random(252, 24);  status += test_pluq_random(256, 256);  status += test_pluq_random(1024, 1022);  status += test_pluq_random(1024, 1024);  status += test_pluq_random(128, 1280);  status += test_pluq_random(128, 130);  status += test_pluq_random(132, 132);  status += test_pluq_random(150, 151);  status += test_pluq_random(252, 2);  status += test_pluq_random(256, 251);  status += test_pluq_random(1024, 1025);  status += test_pluq_random(1024, 1021);  if (!status) {    printf("All tests passed./n");    return 0;  } else {    return -1;  }}
开发者ID:alexanderdreyer,项目名称:polybori-debian,代码行数:79,


示例5: main

int main(int argc, char **argv){	int opt;	int fd;	int max_blocks = 0;	char *endptr;	unsigned int seed = 123;	int reboot = 0;	int direct_io = 0;	long int test = 1;	long int tmp;	int ret = 0;	int flags = O_RDWR|O_CREAT|O_TRUNC;	if (argc < 2)		usage();	fd = open("/dev/urandom", O_RDONLY);	if (fd >= 0) {		read(fd, &seed, sizeof(seed));		close(fd);	}	while ((opt = getopt(argc, argv, "s:rdt:")) != -1) {		switch (opt) {		case 's':			tmp = strtol(optarg, &endptr, 10);			if (tmp == LONG_MAX || endptr == optarg)				usage();			seed = tmp;			break;		case 'r':			reboot = 1;			break;		case 'd':			direct_io = 1;			break;		case 't':			test = strtol(optarg, &endptr, 10);			if (test == LONG_MAX || endptr == optarg)				usage();			break;		default:			usage();		}	}	if (optind >= argc)		usage();	fname = argv[optind];	if (!fname)		usage();	printf("Random seed is %u/n", seed);	srandom(seed);	if (direct_io) {		flags |= O_DIRECT;		ret = posix_memalign((void **)&buf, getpagesize(), 4096);		if (ret)			buf = NULL;	} else {		buf = malloc(4096);	}	if (!buf) {		fprintf(stderr, "Error allocating buf: %d/n", errno);		return 1;	}	test_fd = open(fname, flags, 0644);	if (test_fd < 0) {		fprintf(stderr, "Error opening file %d (%s)/n", errno,			strerror(errno));		return 1;	}	switch (test) {	case 1:		ret = test_one(&max_blocks);		break;	case 2:		ret = test_two(&max_blocks);		break;	case 3:		ret = test_three(&max_blocks, 0, 0, 0, 0);		break;	case 4:		ret = test_three(&max_blocks, 1, 0, 0, 0);		break;	case 5:		ret = test_three(&max_blocks, 0, 1, 0, 0);		break;	case 6:		ret = test_three(&max_blocks, 1, 1, 0, 0);		break;	case 7:		ret = test_three(&max_blocks, 0, 0, 1, 0);		break;//.........这里部分代码省略.........
开发者ID:vdmfernandes,项目名称:xfstests,代码行数:101,


示例6: main

int main(int argc, char **argv){	if(argc < 4) {		printf("Usage/n");		printf("    test random <heap> <vertices> [seed] [edgechance] [maxweight] [source]/n");		printf("    test dkmax <heap> <vertices>/n");		printf("    test dkmax2 <heap> <vertices>/n");		printf("        Heaptypes:  bin, fib, pq/n");		exit(1);	}		char *heap_name = malloc(10*sizeof(char));	unsigned int (*dijkstra)(unsigned int num_vertices, unsigned int source, unsigned int * w, unsigned int ** edges, unsigned int *bops);	if(strcmp(argv[2], "bin") == 0) {		heap_name = "Binary";		dijkstra = dijkstra_bin;	} else if(strcmp(argv[2], "fib") == 0) {		heap_name = "Fibonacci";		dijkstra = dijkstra_fib;	} else if(strcmp(argv[2], "pq") == 0) {		heap_name = "Primitive";		dijkstra = dijkstra_pq;	} else {		printf("Unknown heap type '%s'/n", argv[2]);		exit(2);	}		unsigned int vertices = (unsigned int)strtoul(argv[3], NULL, 10);	unsigned int source = 0;	unsigned int *weights;	unsigned int **edges = malloc(vertices * sizeof(unsigned int *));	if(strcmp(argv[1], "random") == 0) {		unsigned int seed;		if(argc > 4 && argv[4]) {			seed = (unsigned int)strtoul(argv[4], NULL, 10);			srandom(seed);		} else {			srandom(time(NULL));			seed = random()%99999999;		}				unsigned int edge_chance = 15;		if(argc > 5)			edge_chance = (unsigned int)strtoul(argv[5], NULL, 10);				unsigned int max_weight = 20;		if(argc > 6)			max_weight = (unsigned int)strtoul(argv[6], NULL, 10);				source = random()%vertices;		if(argc > 7)			source = (unsigned int)strtoul(argv[7], NULL, 10);				weights = generate_graph(vertices, edge_chance, max_weight, seed);				printf("Reticulating splines./n");		unsigned int *t_edges = malloc(vertices * sizeof(unsigned int));		int i, j;		for (i = 0; i < vertices; i++) {			unsigned int count = 0;			for (j = 0; j < vertices; j++)				if (weights[(i * vertices) + j])					t_edges[++count] = j;						edges[i] = malloc((count+1) * sizeof(unsigned int));			edges[i][0] = count;			for (j = 1; j <= count; j++)				edges[i][j] = t_edges[j];		}		free(t_edges);	} else if(strcmp(argv[1], "dkmax") == 0) {		weights = generate_decrease_key_max(vertices);				printf("Reticulating splines./n");		unsigned int *t_edges = malloc(vertices * sizeof(unsigned int));		int i, j;		for (i = 0; i < vertices; i++) {			unsigned int count = 0;			for (j = 0; j < vertices; j++)				if (weights[(i * vertices) + j])					t_edges[++count] = j;			edges[i] = malloc((count+1) * sizeof(unsigned int));			edges[i][0] = count;			for (j = 1; j <= count; j++)				edges[i][j] = t_edges[j];		}		//free(t_edges);	} else if (strcmp(argv[1], "dkmax2") == 0){		weights = generate_decrease_key_max2(vertices);		printf("Reticulating splines./n");		unsigned int *t_edges = malloc(vertices * sizeof(unsigned int));		edges = malloc(vertices * sizeof(unsigned int *));		int i, j;		for (i = 0; i < vertices; i++) {			unsigned int count = 0;			for (j = 0; j < vertices; j++){				if (weights[(i * vertices) + j])					t_edges[++count] = j;//.........这里部分代码省略.........
开发者ID:hvidgaard,项目名称:AADS,代码行数:101,


示例7: login_query

static voidlogin_query(){	char		uid       [IDLEN + 1], passbuf[PASSLEN];	int		attempts;	char		genbuf    [200];	resolve_utmp();	attempts = utmpshm->number;	clear();#ifdef CAMERA	film_out(time(0) % 5, 0);#else	show_file("etc/Welcome0", 0, 20, ONLY_COLOR);#endif	if (attempts >= MAXACTIVE) {		pressanykey("目前站上人
C++ srandomdev函数代码示例
C++ srand48函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。