本文整理汇总了C++中random_int函数的典型用法代码示例。如果您正苦于以下问题:C++ random_int函数的具体用法?C++ random_int怎么用?C++ random_int使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了random_int函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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];
}
示例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;
}
}
示例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;
}
}
}
}
示例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;
}
示例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;
}
示例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);
}