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); }
/* * 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); }
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); }
/* 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]; } } }
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); }
/* * 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); }
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; } }
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); }
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; }
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; }
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); }
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); }
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 }
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(); }
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); } }
void golla2(int i) { static int packet_count = 0; if (packet_count < SLOT_SIZE) slot[packet_count] = i; else { if ((rand_int(packet_count + 1)) < SLOT_SIZE) slot[rand_int(SLOT_SIZE)] = i; } packet_count++; }
static void tstress(int num) { unsigned int n, skips, lock_ops, unlock_ops, unlockf_ops, cancel_ops; int i; struct lk *lk; n = skips = lock_ops = unlock_ops = unlockf_ops = cancel_ops = 0; sts_eunlock = sts_ecancel = sts_etimedout = sts_edeadlk = sts_eagain = sts_other = sts_zero = 0; bast_unlock = bast_skip = 0; noqueue = 0; ignore_bast = 1; quiet = 0; if (!timeout) timeout = 4; if (!minhold) minhold = 5; while (!stress_stop) { if (stress_delay) usleep(stress_delay); process_libdlm(); tstress_unlocks(); if (++n == num) { if (all_unlocks_done()) break; else continue; } i = rand_int(0, maxn-1); lk = get_lock(i); if (!lk) continue; if (lk->wait_ast || lk->grmode > -1) continue; lock(i, rand_int(0, 5)); lock_ops++; printf("%8x: lock %3d\t%x\n", n, i, lk->lksb.sb_lkid); } printf("ops: skip %d lock %d unlock %d unlockf %d cancel %d\n", skips, lock_ops, unlock_ops, unlockf_ops, cancel_ops); printf("bast: unlock %u skip %u\n", bast_unlock, bast_skip); printf("ast status: eunlock %d ecancel %d etimedout %d edeadlk %d eagain %d\n", sts_eunlock, sts_ecancel, sts_etimedout, sts_edeadlk, sts_eagain); printf("ast status: zero %d other %d\n", sts_zero, sts_other); }
Venom::Venom(GLuint shader, float _x, float _y, float _z) { shader_programme = shader; dead = false; home = false; distance_moved = 0; dead_time = 0; moving_dir = glm::vec3(rand_int(-1, 1), 0, rand_int(-1, 1)); x = _x; y = _y; z = _z; init(); }
Particule::Particule(sf::Vector2i window_size, GameConfiguration * gameConfig, AudioConfiguration * audio) : shape(1, rand_int(3, 5)) { _radius_base = rand_float(0.05, 0.3); _window_size = window_size; _gameConfig = gameConfig; _audio = audio; speed = sf::Vector2f(rand_float(-0.5, 0.5),rand_float(-0.5, 0.1)); shape.setPosition(sf::Vector2f(rand_float(0.0f, (float) (window_size.x)),rand_float(0.0f, (float) (window_size.y)))); //shape.setPosition(sf::Vector2f(10,100)); shape.setFillColor(sf::Color(rand_int(0, 96), rand_int(0, 96), rand_int(0, 96))); }
void evolve_table_cyclic_boundary ( int M, int N, int** table, double beta, long long niter ) { int i,j; for (long long k = 0; k < niter; k++){ for (i=0;i<M;i++) for (j=0;j<N;j++) //modify_cluster (size,table,rand_int(size-1), rand_int(size-1),beta); modify_cell (M, N,table,rand_int(M), rand_int(N),beta); //modify_cell (size,table,i,j,beta); } }
vec2i spawn_position(int index, int scientist) { switch (index) { case 0: // top left gantry if (scientist) { return vec2i_create(90,80); } switch (rand_int(3)) { case 0: // middle return vec2i_create(90,80); case 1: // left arm return vec2i_create(30,80); case 2: // right arm return vec2i_create(120,80); } case 1: // top right gantry if (scientist) { return vec2i_create(230,80); } switch (rand_int(3)) { case 0: // middle return vec2i_create(230,80); case 1: // left arm return vec2i_create(200,80); case 2: //right arm return vec2i_create(260,80); } case 2: // middle left gantry return vec2i_create(90, 118); case 3: // middle right gantry return vec2i_create(230,118); //return vec2i_create(280,118); // only welder can use the following case 4: // bottom left gantry return vec2i_create(90,150); case 5: // bottom right gantry return vec2i_create(230,150); default: return vec2i_create(160, 200); } }
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); grid->input_mov = 0; grid->input_rep = 0; grid->input_rot = 0; grid->stone_count++; }
void stars_init(void) { int x; register_event("draw ortho", draw_stars); register_event("timer delta", update_stars); for(x=0; x<NUM_STARS; x++) { stars[x].v[0] = rand_int(640); stars[x].v[1] = rand_int(480); stars[x].v[2] = rand_float(); stars[x].v[3] = rand_float(); } }
void TetrominoRandomizer::regen() { nbTetrominoReserve = 7; for (int i=0; i<7; i++) randTetrominoType[i] = i; for (int i=0; i<20; i++) { int r1 = rand_int(0, 6), r2; do { r2 = rand_int(0, 6); } while (r1 == r2); swap(randTetrominoType[r1], randTetrominoType[r2]); } }
void::Crow::update(glm::vec3 target, float delta_time) { if (dead) { // reset position x = rand_int(x-100, x+100); z = rand_int(z-100, z+100); dead = false; } else { //glm::vec3 turn_towards = target; vec3 new_flying_dir = target - glm::vec3(x, y, z); if (venom.home) { new_flying_dir = -new_flying_dir; // fly away from venom instead } float distance = sqrtf(dot(new_flying_dir, new_flying_dir)); if (distance < 3) { venom.dead = true; } flying_dir = normalize(new_flying_dir); float dx = delta_time * move_speed * flying_dir.x; float dz = delta_time * move_speed * flying_dir.z; x += dx; z += dz; distance_moved += delta_time; } float crow_wing_angle = sin(distance_moved * crow_wing_speed) * 15; // move body crow_body_T = glm::translate(glm::mat4(1.0), glm::vec3(x, y, z)); crow_body_R = glm::rotate(glm::mat4(1.0), float(atan2(-flying_dir.x, -flying_dir.z) * 180 / 3.14), glm::vec3(0, 1.0, 0)); crow_body_M = crow_body_T * crow_body_R; // move left wing crow_left_wing_local_T = glm::translate(glm::mat4(1.0), glm::vec3(std::max(crow_wing_angle/500*move_speed, 0.0f), 0.0, 0.0)); crow_left_wing_local_R = glm::rotate(glm::mat4(1.0), crow_wing_angle, glm::vec3(0.0, 0.0, 1.0)); crow_left_wing_M = crow_body_M * crow_left_wing_local_T * crow_left_wing_local_R; // move right wing crow_right_wing_local_T = glm::translate(glm::mat4(1.0), glm::vec3(std::min(-crow_wing_angle/500*move_speed, 0.0f), 0.0, 0.0)); crow_right_wing_local_R = glm::rotate(glm::mat4(1.0), -crow_wing_angle, glm::vec3(0.0, 0.0, 1.0)); crow_right_wing_M = crow_body_M * (crow_right_wing_local_T * crow_right_wing_local_R); }
static void prob_bang(t_prob *x) { if (x->x_state) /* CHECKED: no output after clear */ { int rnd = rand_int(&x->x_seed, x->x_state->tr_count); t_probtrans *trans = x->x_state->tr_nexttrans; if (trans) { for (trans = x->x_state->tr_nexttrans; trans; trans = trans->tr_nexttrans) if ((rnd -= trans->tr_count) < 0) break; if (trans) { t_probtrans *nextstate = trans->tr_suffix; if (nextstate) { outlet_float(((t_object *)x)->ob_outlet, nextstate->tr_value); x->x_state = nextstate; } else loudbug_bug("prob_bang: void suffix"); } else loudbug_bug("prob_bang: search overflow"); } else { outlet_bang(x->x_bangout); if (x->x_default) /* CHECKED: stays at dead-end if no default */ x->x_state = x->x_default; } } }
/* --- Function: void create_random_nodes(Slist list, int nr_of_nodes) --- */ void create_random_nodes(Slist list, int nr_of_nodes) { int i=0, *pi, retval; my_clearscrn(); /* Initialize the list.. */ printf("--- CREATED A SINGLY-LINKED LIST(%d NODES)- RANDOM INTEGER DATA ---", NR_OF_ITEMS); do { pi = (int *)malloc(sizeof(int)); MALCHK(pi); *pi = rand_int(1,50); retval=SLISTinsnext(list, NULL, pi); assert(retval == OK); } while (++i < nr_of_nodes); /* Display the list... */ printf("\n\nCurrent list status(%d nodes): ", SLISTsize(list)); SLISTtraverse(list, print, SLIST_FWD); prompt_and_pause("\n\n"); }
Point3D Sampler::sample_sphere(void) { if (count % num_samples == 0) // start of a new pixel jump = (rand_int() % num_sets) * num_samples; return (sphere_samples[jump + shuffled_indices[jump + count++ % num_samples]]); }
Point2D Sampler::sample_unit_disk(void) { if (count % num_samples == 0) // start of a new pixel jump = (rand_int() % num_sets) * num_samples; return (disk_samples[jump + shuffled_indices[jump + count++ % num_samples]]); }
Point2D Sampler::sample_unit_square(void) { if (count % num_samples == 0) // start of a new pixel jump = (rand_int() % num_sets) * num_samples; // random index jump initialised to zero in constructor return (samples[jump + shuffled_indices[jump + count++ % num_samples]]); }