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


C++ rng_int函数代码示例

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


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

示例1: assert

unit *addplayer(region * r, faction * f)
{
    unit *u;
    const char * name;

    assert(r->land);
    if (rpeasants(r) < PEASANT_MIN) {
        rsetpeasants(r, PEASANT_MIN + rng_int() % (PEASANT_MAX - PEASANT_MIN));
    }

    assert(f->units == NULL);
    faction_setorigin(f, 0, r->x, r->y);
    u = create_unit(r, f, 1, f->race, 0, NULL, NULL);
    u->thisorder = default_order(f->locale);
    unit_addorder(u, copy_order(u->thisorder));
    name = config_get("rules.equip_first");
    if (!equip_unit(u, name ? name : "first_unit")) {
        /* give every unit enough money to survive the first turn */
        i_change(&u->items, get_resourcetype(R_SILVER)->itype, maintenance_cost(u));
    }
    u->hp = unit_max_hp(u) * u->number;
    fset(u, UFL_ISNEW);
    if (f->race == get_race(RC_DAEMON)) {
        race_t urc;
        const race *rc;
        do {
            urc = (race_t)(rng_int() % MAXRACES);
            rc = get_race(urc);
        } while (rc == NULL || urc == RC_DAEMON || !playerrace(rc));
        u->irace = rc;
    }
    f->lastorders = 0;
    return u;
}
开发者ID:eressea,项目名称:server,代码行数:34,代码来源:faction.c

示例2: scared_by_monster

static void scared_by_monster(unit * u)
{
    int n;

    switch (old_race(u_race(u))) {
    case RC_FIREDRAGON:
        n = rng_int() % 160 * u->number;
        break;
    case RC_DRAGON:
        n = rng_int() % 400 * u->number;
        break;
    case RC_WYRM:
        n = rng_int() % 1000 * u->number;
        break;
    default:
        n = rng_int() % (u->number / 4 + 1);
    }

    if (n > 0) {
        n = lovar(n);
        n = _min(rpeasants(u->region), n);
        if (n > 0) {
            n = scareaway(u->region, n);
            if (n > 0) {
                ADDMSG(&u->region->msgs, msg_message("fleescared",
                                                     "amount unit", n, u));
            }
        }
    }
}
开发者ID:hochl,项目名称:server,代码行数:30,代码来源:monster.c

示例3: main

int main() {
    int i, numIn, n;
    int state;
    double x, y, pi;

    n = 100000000;
    numIn = 0;

    #pragma omp parallel private(state, x, y) reduction(+:numIn) 
    {
        
        state = 25234 + 17 * omp_get_thread_num();
        #pragma omp for
        for (i = 0; i <= n; i++) {
            state = rng_int(state);
            x = (double)rng_doub(1.0, state);
            state = rng_int(state);
            y = (double)rng_doub(1.0, state);
            if (x*x + y*y <= 1) numIn++;
        }
    }
    pi = 4.*numIn / n;
    printf("asdf pi %f\n", pi);
    return 0;
}
开发者ID:CCJY,项目名称:coliru,代码行数:25,代码来源:main.cpp

示例4: calloc

faction *gm_addquest(const char *email, const char *name, int radius,
  unsigned int flags)
{
  plane *pl;
  watcher *w = calloc(sizeof(watcher), 1);
  region *center;
  bool invalid = false;
  int minx, miny, maxx, maxy, cx, cy;
  int x;
  faction *f;

  /* GM playfield */
  do {
    minx = ((rng_int() % (2 * EXTENSION)) - EXTENSION);
    miny = ((rng_int() % (2 * EXTENSION)) - EXTENSION);
    for (x = 0; !invalid && x <= radius * 2; ++x) {
      int y;
      for (y = 0; !invalid && y <= radius * 2; ++y) {
        region *r = findregion(minx + x, miny + y);
        if (r)
          invalid = true;
      }
    }
  } while (invalid);
  maxx = minx + 2 * radius;
  cx = minx + radius;
  maxy = miny + 2 * radius;
  cy = miny + radius;
  pl = create_new_plane(rng_int(), name, minx, maxx, miny, maxy, flags);
  center = new_region(cx, cy, pl, 0);
  for (x = 0; x <= 2 * radius; ++x) {
    int y;
    for (y = 0; y <= 2 * radius; ++y) {
      region *r = findregion(minx + x, miny + y);
      if (!r) {
        r = new_region(minx + x, miny + y, pl, 0);
      }
      freset(r, RF_ENCOUNTER);
      if (distance(r, center) == radius) {
        terraform_region(r, newterrain(T_FIREWALL));
      } else if (r == center) {
        terraform_region(r, newterrain(T_PLAIN));
      } else {
        terraform_region(r, newterrain(T_OCEAN));
      }
    }
  }

  /* watcher: */
  f = gm_addfaction(email, pl, center);
  w->faction = f;
  w->mode = see_unit;
  w->next = pl->watchers;
  pl->watchers = w;

  return f;
}
开发者ID:UweKopf,项目名称:server,代码行数:57,代码来源:gmcmd.c

示例5: terraform_default

static void terraform_default(struct rawmaterial *res, const region * r)
{
#define SHIFT 70
    double modifier =
        1.0 + ((rng_int() % (SHIFT * 2 + 1)) - SHIFT) * ((rng_int() % (SHIFT * 2 +
        1)) - SHIFT) / 10000.0;
    res->amount = (int)(res->amount * modifier);  /* random adjustment, +/- 91% */
    if (res->amount < 1)
        res->amount = 1;
    unused_arg(r);
}
开发者ID:Xolgrim,项目名称:server,代码行数:11,代码来源:resources.c

示例6: demon_skillchanges

/** Talente von Dämonen verschieben sich.
 */
static void demon_skillchanges(void)
{
  region *r;

  for (r = regions; r; r = r->next) {
    unit *u;
    for (u = r->units; u; u = u->next) {
        if (u_race(u) == get_race(RC_DAEMON)) {
        skill *sv = u->skills;
        int upchance = 15;
        int downchance = 10;

        if (fval(u, UFL_HUNGER)) {
          /* hungry demons only go down, never up in skill */
          static int rule_hunger = -1;
          if (rule_hunger < 0) {
            rule_hunger =
              get_param_int(global.parameters, "hunger.demon.skill", 0);
          }
          if (rule_hunger) {
            upchance = 0;
            downchance = 15;
          }
        }

        while (sv != u->skills + u->skill_size) {
          int roll = rng_int() % 100;
          if (sv->level > 0 && roll < upchance + downchance) {
            int weeks = 1 + rng_int() % 3;
            if (roll < downchance) {
              reduce_skill(u, sv, weeks);
              if (sv->level < 1) {
                /* demons should never forget below 1 */
                set_level(u, sv->id, 1);
              }
            } else {
              while (weeks--)
                learn_skill(u, sv->id, 1.0);
            }
            if (sv->old > sv->level) {
              if (verbosity >= 3) {
                log_printf(stdout, "%s dropped from %u to %u:%u in %s\n",
                  unitname(u), sv->old, sv->level, sv->weeks, skillname(sv->id,
                    NULL));
              }
            }
          }
          ++sv;
        }
      }
    }
  }
}
开发者ID:hochl,项目名称:server,代码行数:55,代码来源:randenc.c

示例7: godcurse

static void godcurse(void)
{
    region *r;

    for (r = regions; r; r = r->next) {
        if (is_cursed(r->attribs, C_CURSED_BY_THE_GODS, 0)) {
            unit *u;
            for (u = r->units; u; u = u->next) {
                skill *sv = u->skills;
                while (sv != u->skills + u->skill_size) {
                    int weeks = 1 + rng_int() % 3;
                    reduce_skill(u, sv, weeks);
                    ++sv;
                }
            }
            if (fval(r->terrain, SEA_REGION)) {
                ship *sh;
                for (sh = r->ships; sh;) {
                    ship *shn = sh->next;
                    double dmg = config_get_flt("rules.ship.damage.godcurse", 0.1);
                    damage_ship(sh, dmg);
                    if (sh->damage >= sh->size * DAMAGE_SCALE) {
                        unit *u = ship_owner(sh);
                        if (u)
                            ADDMSG(&u->faction->msgs,
                                   msg_message("godcurse_destroy_ship", "ship", sh));
                        remove_ship(&sh->region->ships, sh);
                    }
                    sh = shn;
                }
            }
        }
    }

}
开发者ID:eressea,项目名称:server,代码行数:35,代码来源:randenc.c

示例8: assert

const terrain_type *random_terrain(const terrain_type * terrains[],
    int distribution[], int size)
{
    int ndistribution = size;
    const terrain_type *terrain;
    int n;

    assert(size > 0);
    if (distribution) {
        ndistribution = 0;
        for (n = 0; n != size; ++n) {
            ndistribution += distribution[n];
        }
    }

    n = rng_int() % ndistribution;
    if (distribution) {
        int i;
        for (i = 0; i != size; ++i) {
            n -= distribution[i];
            if (n < 0)
                break;
        }
        assert(i < size);
        terrain = terrains[i];
    }
    else {
        terrain = terrains[n];
    }
    return terrain;
}
开发者ID:philbooth,项目名称:server,代码行数:31,代码来源:autoseed.c

示例9: malloc

static const terrain_type *chaosterrain(void)
{
    static const terrain_type **types;
    static int numtypes;

    if (numtypes == 0) {
        const terrain_type *terrain;
        for (terrain = terrains(); terrain != NULL; terrain = terrain->next) {
            if (fval(terrain, LAND_REGION) && terrain->herbs) {
                ++numtypes;
            }
        }
        if (numtypes > 0) {
            types = malloc(sizeof(terrain_type *) * numtypes);
            numtypes = 0;
            for (terrain = terrains(); terrain != NULL; terrain = terrain->next) {
                if (fval(terrain, LAND_REGION) && terrain->herbs) {
                    types[numtypes++] = terrain;
                }
            }
        }
    }
    if (numtypes > 0) {
        return types[rng_int() % numtypes];
    }
    return NULL;
}
开发者ID:stm2,项目名称:server,代码行数:27,代码来源:chaos.c

示例10: encounters

void encounters(void)
{
  region *r;

  for (r = regions; r; r = r->next) {
    if (fval(r->terrain, LAND_REGION) && fval(r, RF_ENCOUNTER)) {
      int c = 0;
      unit *u;
      for (u = r->units; u; u = u->next) {
        c += u->number;
      }

      if (c > 0) {
        int i = 0;
        int n = rng_int() % c;

        for (u = r->units; u; u = u->next) {
          if (i + u->number > n)
            break;
          i += u->number;
        }
        assert(u && u->number);
        encounter(r, u);
      }
    }
  }
}
开发者ID:hochl,项目名称:server,代码行数:27,代码来源:randenc.c

示例11: rng_int

static unit *random_unit(const region * r)
{
  int c = 0;
  int n;
  unit *u;

  for (u = r->units; u; u = u->next) {
      if (u_race(u) != get_race(RC_SPELL)) {
      c += u->number;
    }
  }

  if (c == 0) {
    return NULL;
  }
  n = rng_int() % c;
  c = 0;
  u = r->units;

  while (u && c < n) {
      if (u_race(u) != get_race(RC_SPELL)) {
      c += u->number;
    }
    u = u->next;
  }

  return u;
}
开发者ID:hochl,项目名称:server,代码行数:28,代码来源:randenc.c

示例12: rng_int

static order *monster_learn(unit * u)
{
    int c = 0;
    int n;
    skill *sv;
    const struct locale *lang = u->faction->locale;

    /* can these monsters even study? */
    if (!unit_can_study(u)) {
        return NULL;
    }

    /* Monster lernt ein zufälliges Talent aus allen, in denen es schon
     * Lerntage hat. */
    for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
        if (sv->level > 0)
            ++c;
    }

    if (c == 0)
        return NULL;

    n = rng_int() % c + 1;
    c = 0;

    for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
        if (sv->level > 0) {
            if (++c == n) {
                return create_order(K_STUDY, lang, "'%s'", skillname(sv->id, lang));
            }
        }
    }
    return NULL;
}
开发者ID:philbooth,项目名称:server,代码行数:34,代码来源:monsters.c

示例13: arena_weighted_mbind

static void arena_weighted_mbind(void *arena, size_t arena_size,
																 uint16_t *weights, size_t nr_weights) {
	/* compute cumulative sum for weights
	 * cumulative sum starts at -1
	 * the method for determining a hit on a weight i is when the generated
	 * random number (modulo sum of weights) <= weights_cumsum[i]
	 */
	int64_t weights_cumsum[nr_weights];
	weights_cumsum[0] = weights[0] - 1;
	for (unsigned int i = 1; i < nr_weights; i++) {
		weights_cumsum[i] = weights_cumsum[i-1] + weights[i];
	}
	const int32_t weight_sum = weights_cumsum[nr_weights-1]+1;
	const int pagesize = getpagesize();

	uint64_t mask = 0;
	char *q = (char *)arena + arena_size;
	rng_init(1);
	for (char *p = arena; p < q; p += pagesize) {
		uint32_t r = rng_int(1<<31) % weight_sum;
		unsigned int node;
		for (node = 0; node < nr_weights; node++) {
			if (weights_cumsum[node] >= r) {
				break;
			}
		}
		mask = 1 << node;
		if (mbind(p, pagesize, MPOL_BIND, &mask, nr_weights, MPOL_MF_STRICT)) {
			perror("mbind");
			exit(1);
		}
		*p = 0;
	}
}
开发者ID:jichuan2k,项目名称:multichase,代码行数:34,代码来源:arena.c

示例14: scareaway

static int scareaway(region * r, int anzahl)
{
    int n, p, diff = 0, emigrants[MAXDIRECTIONS];
    direction_t d;

    anzahl = _min(_max(1, anzahl), rpeasants(r));

    /* Wandern am Ende der Woche (normal) oder wegen Monster. Die
     * Wanderung wird erst am Ende von demographics () ausgefuehrt.
     * emigrants[] ist local, weil r->newpeasants durch die Monster
     * vielleicht schon hochgezaehlt worden ist. */

    for (d = 0; d != MAXDIRECTIONS; d++)
        emigrants[d] = 0;

    p = rpeasants(r);
    assert(p >= 0 && anzahl >= 0);
    for (n = _min(p, anzahl); n; n--) {
        direction_t dir = (direction_t) (rng_int() % MAXDIRECTIONS);
        region *rc = rconnect(r, dir);

        if (rc && fval(rc->terrain, LAND_REGION)) {
            ++diff;
            rc->land->newpeasants++;
            emigrants[dir]++;
        }
    }
    rsetpeasants(r, p - diff);
    assert(p >= diff);
    return diff;
}
开发者ID:hochl,项目名称:server,代码行数:31,代码来源:monster.c

示例15: demon_skillchange

/** Talente von Daemonen verschieben sich.
*/
void demon_skillchange(unit *u)
{
    skill *sv = u->skills;
    int upchance = 15, downchance = 10;
    static int config;
    static bool rule_hunger;
    static int cfgup, cfgdown;

    if (config_changed(&config)) {
        rule_hunger = config_get_int("hunger.demon.skills", 0) != 0;
        cfgup = config_get_int("skillchange.demon.up", 15);
        cfgdown = config_get_int("skillchange.demon.down", 10);
    }
    if (cfgup == 0) {
        /* feature is disabled */
        return;
    }
    upchance = cfgup;
    downchance = cfgdown;

    if (fval(u, UFL_HUNGER)) {
        /* hungry demons only go down, never up in skill */
        if (rule_hunger) {
            downchance = upchance;
            upchance = 0;
        }
    }

    while (sv != u->skills + u->skill_size) {
        int roll = rng_int() % 100;
        if (sv->level > 0 && roll < upchance + downchance) {
            int weeks = 1 + rng_int() % 3;
            if (roll < downchance) {
                reduce_skill(u, sv, weeks);
                if (sv->level < 1) {
                    /* demons should never forget below 1 */
                    set_level(u, sv->id, 1);
                }
            }
            else {
                learn_skill(u, sv->id, STUDYDAYS * u->number * weeks);
            }
        }
        ++sv;
    }
}
开发者ID:ennorehling,项目名称:eressea,代码行数:48,代码来源:study.c


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