本文整理汇总了C++中rand_int函数的典型用法代码示例。如果您正苦于以下问题:C++ rand_int函数的具体用法?C++ rand_int怎么用?C++ rand_int使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rand_int函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: put_stones
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);
}
示例2: monster_critical
/*
* 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);
}
示例3: placemarble
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);
}
示例4: search
/* 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];
}
}
}
示例5: generate_interfaces
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);
}
示例6: confuse_dir
/*
* 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);
}
示例7: rand_float
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;
}
}
示例8: measure_susceptibility_cluster
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);
}
示例9: main
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;
}
示例10: get_random_walkable_node
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;
}
示例11: new_stone
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);
}
示例12: cria_num_primos
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);
}
示例13: rand_int
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
}
示例14: rand_int
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();
}
示例15: evolve_table_pm_boundary
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);
}
}