本文整理汇总了C++中random_int函数的典型用法代码示例。如果您正苦于以下问题:C++ random_int函数的具体用法?C++ random_int怎么用?C++ random_int使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了random_int函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: pingpong_mutate_shift
void pingpong_mutate_shift(population *pop, entity *mother, entity *son)
{
int i, j, k; /* Team members. */
int tmp; /* For swapping i and j. */
/* Copy chromosomes of parent to offspring. */
memcpy( son->chromosome[0],
mother->chromosome[0],
pop->len_chromosomes*sizeof(int) );
i = random_int(9);
do
{
j = random_int(9);
} while(i==j);
if (i>j)
{
tmp = ((int *)son->chromosome[0])[j];
for (k=j; k<i; k++)
{
((int *)son->chromosome[0])[k] = ((int *)son->chromosome[0])[k+1];
}
((int *)son->chromosome[0])[i] = tmp;
}
else
{
tmp = ((int *)son->chromosome[0])[j];
for (k=j; k>i; k--)
{
((int *)son->chromosome[0])[k] = ((int *)son->chromosome[0])[k-1];
}
((int *)son->chromosome[0])[i] = tmp;
}
return;
}
开发者ID:versionzero,项目名称:gaul,代码行数:38,代码来源:pingpong9.c
示例2: init
void init(void)
{
fault_handling_setup();
reset_callback_register();
nap_version_check();
nap_auth_check();
nap_callbacks_setup();
rng_setup();
srand(random_int());
stm_unique_id_callback_register();
}
开发者ID:Paakkit,项目名称:piksi_firmware,代码行数:14,代码来源:init.c
示例3: generate_terminal_node
Node* generate_terminal_node(std::mt19937& random, bool is_ghost)
{
if (is_ghost)
{
switch (random_int(random, 0, 2))
{
case 0: return createNodeFromInt(random, Constant); break;
case 1: return createNodeFromInt(random, GhostToGhost); break;
case 2: return createNodeFromInt(random, GhostToPacman); break;
}
}
else
{
switch (random_int(random, 0, 3))
{
case 0: return createNodeFromInt(random, Constant); break;
case 1: return createNodeFromInt(random, PacmanToDot); break;
case 2: return createNodeFromInt(random, PacmanToGhost); break;
case 3: return createNodeFromInt(random, PacmanDotsEaten); break;
}
}
return nullptr;
}
开发者ID:Tarnasa,项目名称:cppPac,代码行数:23,代码来源:TreeGenerators.cpp
示例4: wildfire_mutate_flip
void wildfire_mutate_flip(population *pop, entity *mother, entity *son)
{
int i; /* Map square. */
/* Copy chromosome. */
for(i=0; i<WILDFIRE_X_DIMENSION*WILDFIRE_Y_DIMENSION; i++)
((int *)son->chromosome[0])[i] = ((int *)mother->chromosome[0])[i];
/* Mutation. */
i = random_int(WILDFIRE_X_DIMENSION*WILDFIRE_Y_DIMENSION);
((int *)son->chromosome[0])[i] = !((int *)son->chromosome[0])[i];
return;
}
开发者ID:versionzero,项目名称:gaul,代码行数:14,代码来源:wildfire_forked.c
示例5: list_to_int
pointer list_to_int(pointer a) {
int res=0;
char *dispatch;
if (is_symbol(car(a))) {
dispatch=sym_name(car(a));
if (!strcmp(dispatch,"random"))
return random_int(cadr(a),caddr(a));
else
return Error_1("list>int: unknown dispatch type:",car(a));
}
else
return Error_1("list>int: no symbol:",car(a));
return mk_integer(res);
}
开发者ID:HaikuArchives,项目名称:AMC,代码行数:14,代码来源:amc-miniscm.cpp
示例6: anneal
void anneal(instance *t, solution *s)
{
double temperature = INITIAL_TEMPERATURE;
initialize_solution(t->n, s);
double current_value = solution_cost(s, t);
for (int i = 1; i <= COOLING_STEPS; i++)
{
temperature *= COOLING_FRACTION;
double start_value = current_value;
for (int j = 1; j <= STEPS_PER_TEMP; j++)
{
int i1 = random_int(1, t->n);
int i2 = random_int(2, t->n);
double flip = random_float(0, 1);
double delta = transition(s, t, i1, i2);
double exponent = (-delta / current_value) / (K * temperature);
double merit = pow(E, exponent);
if (delta < 0)
current_value = current_value + delta;
else
if (merit > flip)
current_value = current_value + delta;
else
transition(s, t, i1, i2);
}
if ((current_value - start_value) < 0.0)
temperature = temperature / COOLING_FRACTION;
}
}
开发者ID:emmanouilmatsis,项目名称:the_algorithm_design_manual,代码行数:37,代码来源:anneal.c
示例7: calloc
RTPSession *rtp_new ( int payload_type, Messenger *messenger, int friend_num )
{
RTPSession *retu = calloc(1, sizeof(RTPSession));
if ( !retu ) {
LOGGER_WARNING("Alloc failed! Program might misbehave!");
return NULL;
}
if ( -1 == custom_lossy_packet_registerhandler(messenger, friend_num, payload_type, rtp_handle_packet, retu)) {
LOGGER_ERROR("Error setting custom register handler for rtp session");
free(retu);
return NULL;
}
LOGGER_DEBUG("Registered packet handler: pt: %d; fid: %d", payload_type, friend_num);
retu->version = RTP_VERSION; /* It's always 2 */
retu->padding = 0; /* If some additional data is needed about the packet */
retu->extension = 0; /* If extension to header is needed */
retu->cc = 1; /* Amount of contributors */
retu->csrc = NULL; /* Container */
retu->ssrc = random_int();
retu->marker = 0;
retu->payload_type = payload_type % 128;
retu->dest = friend_num;
retu->rsequnum = retu->sequnum = 0;
retu->ext_header = NULL; /* When needed allocate */
if ( !(retu->csrc = calloc(1, sizeof (uint32_t))) ) {
LOGGER_WARNING("Alloc failed! Program might misbehave!");
free(retu);
return NULL;
}
retu->csrc[0] = retu->ssrc; /* Set my ssrc to the list receive */
/* Also set payload type as prefix */
retu->prefix = payload_type;
/*
*
*/
return retu;
}
开发者ID:Aaron1011,项目名称:toxcore,代码行数:49,代码来源:rtp.c
示例8: test_random
int test_random()
{
int i, j, result = 0;
test_msg_start("Test Random Number Generator - Integers 0 to 100");
random_seed();
j = 0;
while(j < 100000) {
i = random_int(0,100);
if(i < 0 || i > 100) result++;
j++;
}
test_msg_end(result);
return result;
}
开发者ID:NeelPatel21,项目名称:C-Data-Structures,代码行数:15,代码来源:lib_test.c
示例9: dat
void MixtureDataPolicy::add_data(const Ptr<DataType> &d) {
dat().push_back(d);
int max_levels = pkey_->max_levels();
if (max_levels > 0) {
uint h = random_int(0, max_levels - 1);
NEW(CategoricalData, pcat)(h, pkey_);
latent_data().push_back(pcat);
} else {
NEW(CategoricalData, pcat)(uint(0), pkey_);
latent_data().push_back(pcat);
}
if (!known_data_source_.empty()) {
known_data_source_.push_back(-1);
}
}
开发者ID:cran,项目名称:Boom,代码行数:15,代码来源:MixtureDataPolicy.cpp
示例10: random_int
const GIndividual* GPopulation::choose_individual() const
{
if (gd.selection_method == GenDef::SELECTION_TOURNAMENT)
{
const GIndividual* a1 = individuals[ random_int( individuals.size() ) ];
const GIndividual* a2 = individuals[ random_int( individuals.size() ) ];
if (gd.use_parsimony &&
a1->raw_fitness >= gd.parsimony_threshhold &&
a2->raw_fitness >= gd.parsimony_threshhold)
{
if (fabs( a1->raw_fitness - a2->raw_fitness ) <= 1.0)
{
if ( a1->alg->num_children() < a2->alg->num_children() )
return a1;
else
return a2;
}
}
if (a1->raw_fitness > a2->raw_fitness)
return a1;
else
return a2;
}
else // fitness proportionate
{
double f = static_cast<double>(random_float( 1.0 ));
for( unsigned i = 0; i < individuals.size(); i++ )
{
f -= individuals[i]->normalized_fitness;
if (f <= 0.0f)
return individuals[i];
}
}
return individuals[0];
}
开发者ID:alucardxlx,项目名称:polserver-zulu,代码行数:36,代码来源:treegen.cpp
示例11: addenemy
void addenemy(unsigned short type) {
int i; enemy *typ;
if (type >= sizeof(enemy_list)) type = sizeof(enemy_list)-1;
typ = (enemy*)&enemy_list[type];
for (i = 0; i < MAX_ENEMIES; i++) {
enemy_ref *curr = &enemies[i];
if (curr->health >= 0) continue;
curr->type = typ;
curr->health = typ->start_health;
curr->counter = 0;
if (typ->start_x < 0)
curr->x = (random_int() % (127-(typ->size<<1))) +
typ->size + 1;
else
curr->x = typ->start_x;
if (typ->start_y < 0)
curr->y = (random_int() % (95-(typ->size<<1))) +
typ->size + 1;
else
curr->y = typ->start_y;
break;
}
}
开发者ID:kilogram,项目名称:EE319K,代码行数:24,代码来源:actor.c
示例12: choose_reduced_pilots
void choose_reduced_pilots()
{
int i, reduced, count, num_pilots = 2 * m;
if (k > 0) {
reduced = (num_pilots * k / 100.0);
count = 0;
while (count < reduced) {
i = random_int(0, num_pilots - 1);
if (!pilots[i]->reduce) {
++count;
pilots[i]->reduce = 1;
}
}
}
}
开发者ID:dacortez,项目名称:ep1_concorrente,代码行数:16,代码来源:ep1.c
示例13: random_array
static int * random_array (int minval, int maxval, size_t len)
{
int * arr;
int * ii;
arr = malloc (len * sizeof(int));
if (NULL == arr) {
err (EXIT_FAILURE, __FILE__": %s: malloc", __func__);
}
for (ii = arr; len > 0; ++ii, --len) {
*ii = random_int (minval, maxval);
}
return arr;
}
开发者ID:poftwaresatent,项目名称:da4002,代码行数:16,代码来源:test-sorting-algo.c
示例14: random_int
void CNetTokenManager::GenerateSeed()
{
static const NETADDR NullAddr = { 0 };
m_PrevSeed = m_Seed;
for(int i = 0; i < 2; i++)
{
m_Seed <<= 32;
m_Seed ^= random_int();
}
m_PrevGlobalToken = m_GlobalToken;
m_GlobalToken = GenerateToken(&NullAddr);
m_NextSeedTime = time_get() + time_freq() * m_SeedTime;
}
开发者ID:Redix,项目名称:teeworlds,代码行数:16,代码来源:network_token.cpp
示例15: js_event_start_wait_random_func
JSBool js_event_start_wait_random_func(JSContext *cx,JSObject *j_obj,uintN argc,jsval *argv,jsval *rval)
{
int min,max,tick;
min=JSVAL_TO_INT(argv[0]);
max=JSVAL_TO_INT(argv[1]);
tick=random_int(abs(max-min))+min;
if (!timers_add(&js.attach,tick,JSVAL_TO_INT(argv[2]),NULL,timer_mode_single)) {
*rval=JSVAL_FALSE;
}
else {
*rval=JSVAL_TRUE;
}
return(JS_TRUE);
}
开发者ID:prophile,项目名称:dim3,代码行数:17,代码来源:script_event.c
示例16: generate_tree_up_to
Node* generate_tree_up_to(std::mt19937& random, int max_levels, bool is_ghost)
{
if (max_levels <= 0) return nullptr;
if (max_levels == 1)
{
return generate_terminal_node(random, is_ghost);
}
else
{
Node* parent = generate_parent_node(random);
for (int child_index = 0; child_index < parent->GetMinChildren(); ++child_index)
{
parent->children.emplace_back(generate_tree(random, random_int(random, 1, max_levels - 1), is_ghost));
}
return parent;
}
}
开发者ID:Tarnasa,项目名称:cppPac,代码行数:17,代码来源:TreeGenerators.cpp
示例17: screen_fx_random
void screen_fx_random(){
int x, y;
random_seed();
for(x=0; x < WIDTH; x++){
for(y = 0; y < HEIGHT; y++){
s[x][y].bg_bl = (float)random_int(1,10000)/10000;
s[x][y].bg_rd = (float)random_int(1,10000)/10000;
s[x][y].bg_gr = (float)random_int(1,10000)/10000;
s[x][y].fg_bl = (float)random_int(1,10000)/10000;
s[x][y].fg_rd = (float)random_int(1,10000)/10000;
s[x][y].fg_gr = (float)random_int(1,10000)/10000;
s[x][y].ch = random_int(0, 128);
}
}
}
开发者ID:steven-schronk,项目名称:MicroWars,代码行数:15,代码来源:gfx.c
示例18: g
void robot_manager::add_user(room_user uinfo)
{
guard g(m_mutex);
bool is_ok = false;
do
{
if(uinfo.coin < config_manager::instance()->get_ac().less_coin)
{
break;
}
else if(config_manager::instance()->get_ac().max_coin > 0 &&
uinfo.coin > config_manager::instance()->get_ac().max_coin)
{
break;
}
is_ok = true;
} while (false);
if(!is_ok)
{
if(!cfg_inst->is_ai_auto_supplement())
{
db_thread::instance()->on_logout(uinfo.uid);
return;
}
int coin = random_int(cfg_inst->ai_supplement_from(), cfg_inst->ai_supplement_to());
int dc = (int)(coin - uinfo.coin);
uinfo.coin = coin;
db_thread::instance()->on_add_coin(AI_SUPPLEMENT, uinfo.uid, dc);
}
map<unsigned int, room_user>::iterator i;
i = m_robot.find(uinfo.uid);
if(i == m_robot.end())
{
m_robot[uinfo.uid] = uinfo;
m_idle.push(&m_robot[uinfo.uid]);
i = m_robot.find(uinfo.uid);
}
else
{
i->second.coin = uinfo.coin;
i->second.vip = uinfo.vip;
}
}
开发者ID:mashaolin88,项目名称:code,代码行数:45,代码来源:user_manager.cpp
示例19: random_int_permutation
GAULFUNC void random_int_permutation(const int size, int *iarray, int *oarray)
{
int i,j=0; /* Loop variables over arrays. */
int pos; /* Randomly selected index. */
if (!iarray || !oarray) die("NULL pointer to int array passed.");
for (i=size-1; i>0; i--)
{
pos = random_int(i);
oarray[j++] = iarray[pos];
iarray[pos] = iarray[i];
}
oarray[j] = iarray[0];
return;
}
开发者ID:versionzero,项目名称:gaul,代码行数:18,代码来源:random_util.c
示例20: Project
Project(Display *display, Player *player)
: NewWorldScreen(display, player)
, bitmaps("data")
, motion()
, tile_index()
{
level = new Level();
current_map = new Map();
level->maps.push_back(current_map);
tile_index.load_from_atlas(bitmaps["spritesheet.png"], 21, 21, 2, 2, 1, 1);
current_map->tile_layers.push_back(TileLayer(&tile_index, 60, 60));
// fill our map with random tiles
for (unsigned x=0; x<current_map->tile_layers.back().width; x++)
for (unsigned y=0; y<current_map->tile_layers.back().height; y++)
current_map->tile_layers.back().set_tile(x, y, random_int(0, 200));
}
开发者ID:MarkOates,项目名称:beary2d,代码行数:18,代码来源:main.cpp
注:本文中的random_int函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论