char * get_ench_color(void) { if (halluc) { return (id_potions[get_rand(0, POTIONS - 1)].title); } return (mesg[275]); }
void party_monsters(int rn, int n) { int i, j; short row, col; object *monster; boolean found; n += n; for (i = 0; i < MONSTERS; i++) { mon_tab[i].first_level -= (cur_level % 3); } for (i = 0; i < n; i++) { if (no_room_for_monster(rn)) { break; } for (j = found = 0; ((!found) && (j < 250)); j++) { row = get_rand(rooms[rn].top_row + 1, rooms[rn].bottom_row - 1); col = get_rand(rooms[rn].left_col + 1, rooms[rn].right_col-1); if ((!(dungeon[row][col] & MONSTER)) && (dungeon[row][col] & (FLOOR | TUNNEL))) { found = 1; } } if (found) { monster = gr_monster((object *) 0, 0); if (!(monster->m_flags & IMITATES)) { monster->m_flags |= WAKENS; } put_m_at(row, col, monster); } } for (i = 0; i < MONSTERS; i++) { mon_tab[i].first_level += (cur_level % 3); } }
void fight(dungeon* d) { int damage; if (d->room_npc->hp == 0) { printf("I cannot fight what is not here.\n"); } else { if (alignment(d->room_npc->trait, d->player.trait) == 2) { if(!input("Really fight an ally?", I_BOOL)) { goto END_FIGHT; } } for(;;) { damage = get_rand(d->player.level + d->player.weapon.val + d->player_buff); damage -= d->room_npc->armor.val; damage = (damage<0)?0:damage; printf("I land a blow that deals %d damage.\n", damage); d->room_npc->hp -= damage; damage = get_rand(d->room_npc->level + d->room_npc->weapon.val + d->npc_buff); damage -= d->player.armor.val; damage = (damage<0)?0:damage; printf("%s counters with an attack of %d damage.\n", d->room_npc->name, damage); d->player.hp -= damage; if(d->room_npc->hp <1) { printf("I have conquered over %s!\n", d->room_npc->name); d->player.xp += get_rand(d->room_npc->level) + 1; break; } if(d->player.hp <1) { printf("I have succumbed to battle!\n"); exit(1); } } if(d->cur_room->boss_room) { d->cur_room->boss_room = 0; d->cur_room->chest = 1; } if(d->location == d->end_room) { printf("Congratulations! You have won the game.\n"); exit(0); } } END_FIGHT: ; }
void generate_maze(long col, uint16_t (*cell)[col], long row, struct node *head ,long cl, char (*maze)[cl], long rl) { set_seed(); long cell_count = row*col; long visited_count = 1; // selected col/row long sc = get_rand(col); long sr = get_rand(row); // keep 1 before for visual (knock down wall) long sc_old = sc; long sr_old = sr; /* printf("AT (%ld, %ld)\n", sc, sr); */ int *dir_good = malloc(sizeof(int) * 4); update_maze(cl, maze, rl, sr, sc, sr_old, sc_old, START); while (visited_count < cell_count) { int neighbor_count = find_neighbors(col, cell, row, sc, sr, dir_good); if (neighbor_count > 0) { // pick a direction to go sc_old = sc; sr_old = sr; select_dir(col, cell, &sc, &sr, dir_good, head); update_maze(cl, maze, rl, sr, sc, sr_old, sc_old, PATH); visited_count++; } else { // backtrack struct coord loc = stack_pop(head); if (loc.col > sc) cell[sr][sc] = cell[sr][sc] | 0x2000; // east if (loc.col < sc) cell[sr][sc] = cell[sr][sc] | 0x8000; // west if (loc.row > sr) cell[sr][sc] = cell[sr][sc] | 0x4000; // south if (loc.row < sr) cell[sr][sc] = cell[sr][sc] | 0x1000; // north // new loc update_maze(cl, maze, rl, loc.row, loc.col, sr, sc, BACK); sc = loc.col; sr = loc.row; /* printf("BA (%ld, %ld)\n", sc, sr); */ } } update_maze(cl, maze, rl, sr, sc, sr_old, sc_old, END); free(dir_good); }
static void calculate_setpixel(void) { RECT rect; do { rect.left = get_rand(0, xMax); rect.right = rect.left + 1; rect.top = get_rand(0, yMax); rect.bottom = rect.top + 1; SetPixel(hMemDC, rect.left, rect.top, colors[get_rand(0, num_colors)]); if (TestSemaphore(&PainterRequired) < 0) { InvalidateRect(hWnd, &rect, FALSE); UpdateWindow(hWnd); } } while ((TestSemaphore(&DemoRun)) && (!TestSemaphore(&SingleRun))); if (!TestSemaphore(&SingleRun)); Signal(&Done); }
char gr_obj_char(void) { int r; char *rs = "%!?]=/):*"; r = get_rand(0, 8); return(rs[r]); }
int get_rand() { int r; r=rand(); if ((r == SIG_BLOCK) || (r == SIG_SETMASK) || (r == SIG_UNBLOCK)) { r = get_rand(); } return r; }
int get_rand(int lowBound, int highBound){ // if the lowBound is higher than the highBound, then flip them around and return that. if(highBound < lowBound){ return get_rand(highBound, lowBound); } return ( rand() % (highBound-lowBound+1) ) + lowBound; }
void generate_task_set(int bound) { int i; int capacity = 0; struct timeval ts; gettimeofday(&ts, NULL); srand(ts.tv_usec); // srand((int)time(0)*100); do { task_num = get_rand(MAX_TASK_NUM-1); for(i=0; i<task_num; i++) { period[i] = get_rand(MAX_PERIOD_LENTH)+1; execute[i] = get_rand(period[i]); //while((execute[i] = get_rand(MAX_PERIOD_LENTH))>=period[i]); } lcm_period = lcm(task_num, period, bound); }while (lcm_period==0); for(i=0; i<task_num; i++) { capacity += lcm_period/period[i]*execute[i]; } if (capacity%(lcm_period)) { processor_num = capacity/lcm_period+1; period[task_num] = lcm_period; execute[task_num] = lcm_period*processor_num - capacity; int tmp = gcd_2(period[task_num], execute[task_num]); period[task_num] /= tmp; execute[task_num] /= tmp; task_num += 1; } else { processor_num = capacity/(lcm_period); } return ; }
char get_letter_digit() { int i = get_rand(62); if (i < 26) return get_upper(); else if (i >= 26 && i < 52) return get_lower(); else return get_digit(); }
int get_rand(void) { int r; r = rand(); while ((r == SIG_BLOCK) || (r == SIG_SETMASK) || (r == SIG_UNBLOCK)) { r = get_rand(); } return r; }
static const char * get_ench_color(void) { if (halluc) { return(id_potions[get_rand(0, POTIONS-1)].title); } else if (con_mon) { return("red "); } return("blue "); }
static int get_b_rand() { static int ph=32; /* More bits than we will ever use */ static unsigned long randseq; if(ph > 31) { /* Num bits in return of lrand48() */ ph=0; randseq = get_rand(); } ph++; return ((randseq & (1 << (ph-1))) >> (ph-1)); }
void eat(void) { short ch; short moves; object *obj; char buf[70]; ch = pack_letter(mesg[262], FOOD); if (ch == CANCEL) { return; } if (!(obj = get_letter_object(ch))) { message(mesg[263], 0); return; } if (obj->what_is != FOOD) { message(mesg[264], 0); return; } if ((obj->which_kind == FRUIT) || rand_percent(60)) { moves = get_rand(900, 1100); if (obj->which_kind == RATION) { if (get_rand(1, 10) == 1) { message(mesg[265], 0); } else message(mesg[266], 0); } else { sprintf(buf, mesg[267], fruit); message(buf, 0); } } else { moves = get_rand(700, 900); message(mesg[268], 0); add_exp(2, 1); } rogue.moves_left /= 3; rogue.moves_left += moves; hunger_str[0] = 0; print_stats(STAT_HUNGER); vanish(obj, 1, &rogue.pack); }
void s_con_mon(object *monster) { if (con_mon) { monster->m_flags |= CONFUSED; monster->moves_confused += get_rand(12, 22); message("the monster appears confused", 0); con_mon = 0; } }
size_t city::add_cars(size_t count) { flow_stat fs = this->_flow_stat; // start the flow to make rooms for the new cars this->flow_start(); size_t added_car = 0; // try as much as city can contain in one round count = min(count, this->get_size_streets() * 2 * CONST_STREET_LINES_NO - this->_car_no); FOR(i,0,count, ++) { size_t retry = 0; while(retry++ < this->_cluster_streets.size()) { // random select a cluster vector<street_ptr>& c = this->_cluster_streets[get_rand(0, this->_cluster_streets.size())]; // fail-safe if(!c.size()) continue; // random select a street street_ptr s = c[get_rand(0, c.size())]; // create a new car with unique ID car_ptr cc(new car("CAR-" + std::to_string(this->_car_no++))); // random direction cc->direction(course(int(round(frand())))); // random between [ 3.6km/h , 90km/h ] cc->max_speed(1 + get_rand(0, 25)); // try to bound the car if(s->bound_car(cc, inverse_course(cc->direction())) && ++added_car) break; else { this->_car_no--; } } } // resume the flow status switch(fs) { case STOP: this->flow_stop(); break; case PAUSE: this->flow_pause(); break; case START: break; default: throw runtime_error("invalid flow stat!"); } return added_car; }
char gr_obj_char(void) { short r; const char *rs = "%!?]=/):*"; r = get_rand(0, 8); return(rs[r]); }
size_t data_struct::get_id(point *p) { size_t id; do { id = get_rand(UINT_MAX); } while (points_.count(id)); points_[id] = p; return id; }
static char * names_get_neuter(void) { struct link * chain; if(get_rand(100) < 50) chain = femalechain; else chain = malechain; return names_get_markov(chain); }
size_t data_struct::get_id(edge *e) { size_t id; do { id = get_rand(UINT_MAX); } while (edges_.count(id)); edges_[id] = e; return id; }
int main() { int i; int select[100]; for (i = 0; i < 30; i++) { get_rand(select); } return 0; }
static void swap_mov(GLfloat *a, GLfloat *b) { int j; swap(a,b); j = get_rand(); if (*a < 0) *a = j * -1; else *a = j; }
void maybe_monster_wants_stop( void ) { int rand_sound = get_rand( 20 ); if ( rand_sound > 17 && !is_monster_wet() ) { veiudo.stopped = 1; if ( rand_sound == 18 ) play_owyeh(); else play_madrecita(); usleep(1000000); veiudo.stopped = 0; } }
//{{{void generate_interval_sets(struct interval *A, // must run init_genrand(seed) first void generate_interval_sets(struct interval *A, unsigned int size_A, unsigned int len_A, struct interval *B, unsigned int size_B, unsigned int len_B, unsigned int P) { int i; for (i = 0; i < size_A; i++) { A[i].start = genrand_int32(); A[i].end = A[i].start + len_A; } qsort(A, size_A, sizeof(struct interval), compare_interval_by_start); /* * Draw a number to see if the next interval will intersect or not. * Draw a number to get the next interval, make new interval intersect or * not with the drawn interval based on the first draw. */ int p_max = 100; unsigned int p_mask = get_mask(p_max); unsigned int i_mask = get_mask(size_A); unsigned int l_mask = get_mask(len_A); for (i = 0; i < size_B; i++) { unsigned int next_i = get_rand(size_A, i_mask); unsigned int next_p = get_rand(p_max, p_mask); if (P >= next_p) // intersect // Pick an rand between start and end to start from B[i].start = A[next_i].start + get_rand(len_A, l_mask); else // do not intersect B[i].start = A[next_i].end + get_rand(len_A, l_mask); B[i].end = B[i].start + len_B; } }
void eat(void) { short ch; short moves; object *obj; char buf[70]; ch = pack_letter("eat what?", FOOD); if (ch == CANCEL) { return; } if (!(obj = get_letter_object(ch))) { message("no such item.", 0); return; } if (obj->what_is != FOOD) { message("you can't eat that", 0); return; } if ((obj->which_kind == FRUIT) || rand_percent(60)) { moves = get_rand(950, 1150); if (obj->which_kind == RATION) { message("yum, that tasted good", 0); } else { sprintf(buf, "my, that was a yummy %s", fruit); message(buf, 0); } } else { moves = get_rand(750, 950); message("yuk, that food tasted awful", 0); add_exp(2, 1); } rogue.moves_left /= 3; rogue.moves_left += moves; hunger_str[0] = 0; print_stats(STAT_HUNGER); vanish(obj, 1, &rogue.pack); }
size_t edges_ds::get_id(edge *e) { size_t id; do { id = get_rand(UINT_MAX); } while (edges_.count(id)); edges_[id] = e; edges_by_point_[e->get_vertex_id()] = e; return id; }
put_objects() { short i, n; object *obj; if (cur_level < max_level) { return; } n = coin_toss() ? get_rand(2, 4) : get_rand(3, 5); while (rand_percent(33)) { n++; } if (party_room != NO_ROOM) { make_party(); } for (i = 0; i < n; i++) { obj = gr_object(); rand_place(obj); } put_gold(); }
static void random(void) { int i; Signal(&SingleRun); do { i = get_rand(0, num_routines-1); Routines[i].fn(); } while (TestSemaphore(&DemoRun)); Wait(&SingleRun); Signal(&Done); }
int main() { RNGType rng; boost::normal_distribution<> rdist(1.0,0.5); /**< normal distribution with mean of 1.0 and standard deviation of 0.5 */ boost::variate_generator< RNGType, boost::normal_distribution<> > get_rand(rng, rdist); std::vector<double> v(1000); generate(v.begin(),v.end(),get_rand); return 0; }
static void draw_simple_passage(short row1, short col1, short row2, short col2, short dir) { short i, middle, t; if ((dir == LEFT) || (dir == RIGHT)) { if (col1 > col2) { SWAP(row1, row2); SWAP(col1, col2); } middle = get_rand(col1+1, col2-1); for (i = col1+1; i != middle; i++) { dungeon[row1][i] = TUNNEL; } for (i = row1; i != row2; i += (row1 > row2) ? -1 : 1) { dungeon[i][middle] = TUNNEL; } for (i = middle; i != col2; i++) { dungeon[row2][i] = TUNNEL; } } else { if (row1 > row2) { SWAP(row1, row2); SWAP(col1, col2); } middle = get_rand(row1+1, row2-1); for (i = row1+1; i != middle; i++) { dungeon[i][col1] = TUNNEL; } for (i = col1; i != col2; i += (col1 > col2) ? -1 : 1) { dungeon[middle][i] = TUNNEL; } for (i = middle; i != row2; i++) { dungeon[i][col2] = TUNNEL; } } if (rand_percent(HIDE_PERCENT)) { hide_boxed_passage(row1, col1, row2, col2, 1); } }