当前位置: 首页>>代码示例>>C++>>正文


C++ rand_int函数代码示例

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


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

示例1: put_stones

int				put_stones(t_env *env)
{
	int				type_rate[2];
	int				quantity;
	int				x;
	int				y;
	int				c;
	static int		base_rate[NB_STONE + 1] = {

	RATE_FOOD, RATE_LINEMATE, RATE_DERAUMERE, RATE_SIBUR, RATE_MENDIANE,
	RATE_PHIRAS, RATE_THYSTAME};
	type_rate[0] = -1;
	while (++type_rate[0] < NB_STONE + 1)
	{
		quantity = get_quantity_by_type(env, type_rate[0]) + 1;
		c = 1;
		while (quantity-- && (type_rate[1] = base_rate[type_rate[0]]) >= 0)
		{
			x = rand_int(0, env->opt.x);
			y = rand_int(0, env->opt.y);
			env->map[y][x].ground[type_rate[0]] = 1;
			c += put_one(env, type_rate, x, y);
		}
		printf("%d %s ont ete poses.\n", c, type_to_str(type_rate[0]));
	}
	return (0);
}
开发者ID:Ronan-Duclos,项目名称:Zappy-c-OpenGL-,代码行数:27,代码来源:s_generate_map.c

示例2: monster_critical

/*
 * Critical blow.  All hits that do 95% of total possible damage,
 * and which also do at least 20 damage, or, sometimes, N damage.
 * This is used only to determine "cuts" and "stuns".
 */
static int monster_critical(int dice, int sides, int dam)
{
	int max = 0;
	int total = dice * sides;

	/* Must do at least 95% of perfect */
	if (dam < total * 19 / 20) return (0);

	/* Weak blows rarely work */
	if ((dam < 20) && (rand_int(100) >= dam)) return (0);

	/* Perfect damage */
	if (dam == total) max++;

	/* Super-charge */
	if (dam >= 20)
	{
		while (rand_int(100) < 2) max++;
	}

	/* Critical damage */
	if (dam > 45) return (6 + max);
	if (dam > 33) return (5 + max);
	if (dam > 25) return (4 + max);
	if (dam > 18) return (3 + max);
	if (dam > 11) return (2 + max);
	return (1 + max);
}
开发者ID:BackupTheBerlios,项目名称:nangband,代码行数:33,代码来源:melee1.c

示例3: placemarble

void placemarble()
{
   int x,y,z;

 do 
     {
// x=rand_int(X/2)+X/4; y=rand_int(Y/2)+Y/4; //across aperture in core
 x=rand_int(X); y=rand_int(Y); //across whole substrate
 z=Z-2;
     } while (lattice[x][y][z]>=0);
   
// fprintf(stderr,"d");
   
 while (lattice[x][y][z]==-1 && z>0)
     z--;
 z++;
 if (lattice[x][y][z]>=0)
     fprintf(stderr,"Oh no! I've lost my marbles!\n");
   
// printf("X,Y,Z height of new marble: %d %d %d\n",x,y,z);
   
 marbles[num_snakes].x=x; marbles[num_snakes].y=y; marbles[num_snakes].z=z;
 lattice[x][y][z]=num_snakes;
   
 num_snakes++;
// fprintf(stderr, "Marble placed: %d %d %d num_snakes %d\n",x,y,z,num_snakes);  
}
开发者ID:jarvist,项目名称:Amphisbaena,代码行数:27,代码来源:marbles.c

示例4: search

/* Searching*/
void search(int map[H][W]){
  int s_cnt,i,j,k;
  for(s_cnt=0; s_cnt<STIMES; ++s_cnt){
    /* Change RANGE regularly*/
    if(s_cnt%(STIMES/10)==0)
      RANGE--;
    i=0; /* Reset i and flag[]*/
    for(k=0; k<100; ++k)
      flag[k]=0;
    /* Generate a random start*/
    do{
      tmp[i].row=rand_int(H);
      tmp[i].col=rand_int(W);
    }
    while(getmap(map,tmp[i].row,tmp[i].col)==-1);
    tmp[i].value=getmap(map,tmp[i].row,tmp[i].col);
    flag[tmp[i].value]=1;
    /* Moving*/
    while(tmp[i].value!=-1){
      i++;
      tmp[i]=next(map,tmp,i);
      if(tmp[i].value!=-1)
	flag[tmp[i].value]=1;
    }
    /* If longer route is found*/
    if(i>max){
      max=i;
      for(j=0; j<max; ++j)
	optimum[j]=tmp[j];
    }
  }
}
开发者ID:letrungkien211,项目名称:SoftwareII,代码行数:33,代码来源:10.c

示例5: generate_interfaces

void generate_interfaces(int M, int N, int **table, double beta, int measurements)
{
  long long niter=(long long)((double)(M*10)*log(M)); //size*size*floor(1/fabs(1/beta-2.2698));
  long long i,j;
  long long len;
  interface inter;
  //  interface uniform;
  init_table_pm_third_boundary(M,N,table);
  for (i=0;i<niter;i++) modify_cluster_bc(M,N,table,1+rand_int(M-2), 1+rand_int(N-2), beta);
  printf("{");
  fprintf(stderr,"{");  
  for (i=0;i<measurements; i++){
    inter=get_interface(M,N,table);
    print_interface_to_file(stderr, inter);

    //    uniform=uniformize_interface(inter);
    //    print_interface_to_file(stderr, uniform);

    print_interface_as_ts_to_file(stdout, inter);
    
    free(inter.points);
    //    free(uniform.points);        
    if (i<measurements-1){    
      for (j=0;j<M/10;j++)
	modify_cluster_bc(M,N,table,1+rand_int(M-2), 1+rand_int(N-2), beta);
      printf(",\n");
      fprintf(stderr,",\n");
    }
  }
  printf("}");
  fprintf(stderr,"}");  
  free_2d_array(M,table);
}
开发者ID:naa,项目名称:SLE,代码行数:33,代码来源:interface.c

示例6: confuse_dir

/*
 * Apply confusion, if needed, to a direction
 *
 * Display a message and return TRUE if direction changes.
 */
bool confuse_dir(int *dp)
{
    int dir;

    /* Default */
    dir = (*dp);

    /* Apply "confusion" */
    if (p_ptr->timed[TMD_CONFUSED])
    {
        /* Apply confusion XXX XXX XXX */
        if ((dir == DIR_TARGET) || (rand_int(100) < 75))
        {
            /* Random direction */
            dir = ddd[rand_int(8)];
        }
    }

    /* Notice confusion */
    if ((*dp) != dir)
    {
        /* Warn the user */
        message("You are confused.");

        /* Save direction */
        (*dp) = dir;

        /* Confused */
        return (TRUE);
    }

    /* Not confused */
    return (FALSE);
}
开发者ID:nppangband,项目名称:NPPAngband_QT,代码行数:39,代码来源:target.cpp

示例7: rand_float

void MultiJittered::generateSamples(void) {		
			
	int n = (int)sqrt((float)n_samples);
	float subcell_width = 1.0 / ((float) n_samples);
	
	Point2D fill_point;
	for (int j = 0; j < n_samples * n_sets; j++)
		samples.push_back(fill_point);
	
	for (int p = 0; p < n_sets; p++)
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++) {
				samples[i * n + j + p * n_samples].x = (i * n + j) * subcell_width + rand_float(0, subcell_width);
				samples[i * n + j + p * n_samples].y = (j * n + i) * subcell_width + rand_float(0, subcell_width);
			}
	
	for (int p = 0; p < n_sets; p++)
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++) {
				int k = rand_int(j, n - 1);
				float t = samples[i * n + j + p * n_samples].x;
				samples[i * n + j + p * n_samples].x = samples[i * n + k + p * n_samples].x;
				samples[i * n + k + p * n_samples].x = t;
			}
	
	for (int p = 0; p < n_sets; p++)
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++) {
				int k = rand_int(j, n - 1);
				float t = samples[j * n + i + p * n_samples].y;
				samples[j * n + i + p * n_samples].y = samples[k * n + i + p * n_samples].y;
				samples[k * n + i + p * n_samples].y = t;
		}
}
开发者ID:ghostec,项目名称:White2,代码行数:34,代码来源:MultiJittered.cpp

示例8: measure_susceptibility_cluster

double measure_susceptibility_cluster(int M, int N, int **table, double beta, int measurements)
{
  long long niter=1000;
  long i;

  for (i=0;i<niter;i++) modify_cluster(M,N,table,rand_int(M), rand_int(N), beta);
  
  double mm=0;
  double Msq=0;
  double mc=0;
  double Mfourth=0;
  long E=0;
  for (long i=0; i<measurements; i++){
    mc=((double)calc_magnetization(M,N,table))/(M*N);
    mm=mm+fabs(mc);
    Msq=Msq+mc*mc;
    Mfourth=Mfourth+mc*mc*mc*mc;

    modify_cluster(M,N,table,rand_int(M), rand_int(N), beta);
    //    E=state_energy(M,N,table);
    //    printf("%lf %ld\n",mc, E);
    
  }
  mm=mm/measurements;
  Msq=Msq/measurements;
  Mfourth=Mfourth/measurements;
  
  free_2d_array(M,table);
  printf("%lf %lf %lf %lf %lf \n", 1/beta, mm, beta*(Msq-mm*mm), beta*Msq,1.0-1.0/3.0*Mfourth/(Msq*Msq));
  return beta*(Msq-mm*mm);
}
开发者ID:naa,项目名称:SLE,代码行数:31,代码来源:interface.c

示例9: main

int main() 
{
	int sex1, sex2;
	int birth1, birth2;
	int	count = 0;
	int boy = 0;

	while(count < 1000000) {
		sex1 = rand_int(2);
		sex2 = rand_int(2);

		birth1 = rand_int(7);
		birth2 = rand_int(7);

		if ((sex1 == 0 && birth1 == 2) || (sex2 == 0 && birth2 == 2))  {
		}
		else 
			continue;
		
		count++;

		if (sex1 ==0 && sex2 == 0)
			boy++;
	}
	printf("%d\n", boy);
	return 0;
}
开发者ID:hss440,项目名称:algo1,代码行数:27,代码来源:boy.c

示例10: get_random_walkable_node

internal grid_node* get_random_walkable_node(Grid *grid) {
    grid_node *result;
    do {
        result = get_node_at(grid, rand_int(grid->width), rand_int(grid->height), rand_int(grid->depth));
    } while (!result->walkable);
    return result;
}
开发者ID:NikkiKoole,项目名称:coggies,代码行数:7,代码来源:game.c

示例11: new_stone

static void new_stone(Grid* grid) {
	grid->tick = 0;
	grid->x = GRID_WIDTH / 2 - 2;
	grid->y = -3;
	grid->rot = grid->next_rot;
	grid->stone = grid->next_stone;
	grid->next_rot = 1 << rand_int(3);
	grid->next_stone = rand_int(7);
}
开发者ID:jollyjinx,项目名称:tetrisVI,代码行数:9,代码来源:grid.c

示例12: cria_num_primos

void cria_num_primos(int *p,int *q){
  do{
    *p = rand_int(NUM_MAX);
  }while(primo(*p) == 0);

  do{
    *q = rand_int(NUM_MAX);
  }while((primo(*q) == 0)&&(*p != *q));
  //printf("numero primos %ld %ld\n",*p,*q);
}
开发者ID:romuloccomp,项目名称:rsa_c,代码行数:10,代码来源:rsa_bk.c

示例13: rand_int

void Enemy::enemyAi1() {
	x = .18;						//Movement is set at .18
	y = rand_int(1, 10) * 0.01;		//Y speed is rnadomly set, some go higher
	int rand_x = rand_int(0, 2);	//Randomly generates X coord
	int rand_y = rand_int(0, 2);	//Randomly generates Y coord
	if (rand_x == true)
		x *= -1;					//Randomly goes left/right
	if (rand_y == true)
		y *= -1;					//Randomly goes up/down
}
开发者ID:GOMiCHO,项目名称:Game-PA9,代码行数:10,代码来源:Enemy.cpp

示例14: rand_int

Crow::Crow(GLuint shader, float _x, float _y, float _z) {
	shader_programme = shader;
	dead = false;
	distance_moved = 0;
	flying_dir = glm::vec3(rand_int(-1, 1), 0, rand_int(-1, 1));
	x = _x;
	y = _y;
	z = _z;
	init();
}
开发者ID:KillianMcCabe,项目名称:OpenGL-Game,代码行数:10,代码来源:crow.cpp

示例15: evolve_table_pm_boundary

void evolve_table_pm_boundary ( int M, int N, int** table, double beta, long long niter ) 
{
  int i,j;
  init_table_pm_boundary(M,N,table);

  for (long long k = 0; k < niter; k++){
    for (i=0;i<M;i++)
      for (j=0;j<N;j++)
	modify_cell (M,N,table,1 + rand_int(M-2), 1 + rand_int(N-2),beta);
  }
}
开发者ID:naa,项目名称:SLE,代码行数:11,代码来源:interface.c


注:本文中的rand_int函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。