Beispiel #1
0
/*! First increase or decrease zombie's alertness depending
 on player proximity. Then use alertness to check whether
 the zombie starts actively hunting. */
void update_alertness( game g ) {
    creature Z = g->ZombieListHead;
    int d;
    while( Z != NULL ) {
        chr z = Z->Character;
        // If a zombie sees another zombie hunting, it increases
        // alertness.
        creature Z1 = g->ZombieListHead;
        int num_alert = 0;
        while(Z1 != NULL) {
            chr z1 = Z1->Character; 
            d = distance(z1->pos, z->pos);
            num_alert += z1->alert && d <= zombie_sight_range && d > 0;
            Z1 = Z1->Next;
        }
        if(!z->alert) z->alertness += (randint(0, num_alert) != 0);

        d = distance( g->pc->pos, z->pos );
        if( d <= zombie_sight_range ) {
            if( z->alertness < max_alertness ) {
                z->alertness++;
            }
        } else if( z->alertness > 0 ) {
            if(randint(0, (d - z->alert)/(zombie_sight_range + z->alertness))) z->alertness--;
        }
        int check = randint( 0, max_alertness );
        if( ( z->alert && d > zombie_sight_range ) || ! z->alert ) {
            z->alert = ( check < z->alertness );
        }
        Z = Z->Next;
    }
}
void test() {
  /* Field testing: NWERC 2012 Problem I, Kattis pieceittogether */
  /* TODO: UVa 11294, UVa 10319 */

  for (int n = 1; n <= 15; n++) {
    for (int iter = 0; iter < 100; iter++) {
      int cnt = randint(1, 100);
      vii clauses(cnt);
      for (int i = 0; i < cnt; i++) {
        int a = randint(1, n) * (randint(1, 2) == 1 ? 1 : -1);
        int b = randint(1, n) * (randint(1, 2) == 1 ? 1 : -1);
        clauses[i] = ii(a, b);
      }
      // cout << n << " " << iter << " " << cnt << endl;

      TwoSat ts(n);
      iter(it,clauses) {
        ts.add_or(it->first, it->second);
      }
      if (ts.sat()) {
        vector<bool> is_true(n+1, false);
        // for (int i = 0; i < size(all_truthy); i++) if (all_truthy[i] > 0) is_true[all_truthy[i]] = true;
        rep(i,0,n) if (V[n+(i+1)].val == 1) is_true[i+1] = true;
        for (int i = 0; i < cnt; i++) {
          bool a = is_true[abs(clauses[i].first)],
             b = is_true[abs(clauses[i].second)];
          assert_true((clauses[i].first > 0 ? a : !a) || (clauses[i].second > 0 ? b : !b), true);
        }
      } else {
        for (int j = 0; j < (1<<n); j++) {
Beispiel #3
0
// Spawns a food source by rolling against the spawn rate
void spawn_food_source() {
  if (randreal() <= food_source_spawn_rate) {
    add_food_source(randint(1, grid_size), randint(1, grid_size), food_source_radius, food_source_rations);
    if (global_debug) {
      printf("Spawned food source at %i,%i with %i rations\n", food_list.back()->x, food_list.back()->y, food_list.back()->rations);
    }
  }
}
int test_F_mpn_mul_precache()
{
   mp_limb_t * int1, * int2, * product, * product2;
   F_mpn_precache_t precache;
   mp_limb_t msl;
   int result = 1;
   
   unsigned long count;
   for (count = 0; (count < 30) && (result == 1); count++)
   {
      unsigned long limbs2 = randint(2*FLINT_FFT_LIMBS_CROSSOVER)+1;
      unsigned long limbs1 = randint(2*FLINT_FFT_LIMBS_CROSSOVER)+1;
   
      int1 = (mp_limb_t *) malloc(sizeof(mp_limb_t)*limbs1);

      mpn_random2(int1, limbs1);
   
      F_mpn_mul_precache_init(precache, int1, limbs1, limbs2);   
           
      unsigned long count2;
      for (count2 = 0; (count2 < 30) && (result == 1); count2++)
      {    
#if DEBUG
         printf("%ld, %ld\n",limbs1, limbs2);
#endif

         unsigned long limbs3 = randint(limbs2)+1;
         int2 = (mp_limb_t *) malloc(sizeof(mp_limb_t)*limbs3);
         product = (mp_limb_t *) malloc(sizeof(mp_limb_t)*(limbs1+limbs2));
         product2 = (mp_limb_t *) malloc(sizeof(mp_limb_t)*(limbs1+limbs2));
         
         F_mpn_clear(int2, limbs3);
         mpn_random2(int2, limbs3);
      
         F_mpn_mul_precache(product, int2, limbs3, precache);
         
         if (limbs1 > limbs3) msl = mpn_mul(product2, int1, limbs1, int2, limbs3);
         else msl = mpn_mul(product2, int2, limbs3, int1, limbs1);
      
         unsigned long j;
         for (j = 0; j < limbs1+limbs3 - (msl == 0); j++)
         {
            if (product[j] != product2[j]) result = 0;
         }
      
         free(product2);
         free(product);
         free(int2);
      }
   
      F_mpn_mul_precache_clear(precache);
      
      free(int1);
   }   
   
   return result;
}
Beispiel #5
0
void Population::nextgen()
{
	int nchildren = 0;
	Genome** children = 0;
	
	if (nspecies > MAXSPECIES)
	{
		nspecies = MAXSPECIES;
		listshorten<Species*>(species, nspecies);
	}
	
	for (int i = 0; i < nspecies; i++)
	{
		species[i]->ngenomes /= 2;
		listshorten<Genome*>(species[i]->genomes, species[i]->ngenomes);
		
		int nbreed = globalfitness ? species[i]->avgfitness / globalfitness * NPOP - 1 : 1;
		if (species[i]->ngenomes == 0 || (nspecies > MINSPECIES && ((nbreed <= 0 && nspecies) || (species[i]->staleness > StaleLimit && i != 0))))
		{
			delete species[i];
			listremove<Species*>(species, nspecies, i);
			continue;
		}
		
		for (int j = 0; j < nbreed; j++)
		{
			Genome* child = 0;
			if (randfloat() < CrossoverChance)
			{
				Genome* g1 = species[i]->genomes[randint(0, species[i]->ngenomes-1)];
				Genome* g2 = species[i]->genomes[randint(0, species[i]->ngenomes-1)];
				child = mutate(cross(g1, g2));
			}
			else
			{
				Genome* g1 = species[i]->genomes[randint(0, species[i]->ngenomes-1)];
				child = mutate(g1);
			}
			
			listappend<Genome*>(children, nchildren, child);
		}
		
		species[i]->ngenomes = std::min(KEEPOLD, species[i]->ngenomes);
		listshorten<Genome*>(species[i]->genomes, species[i]->ngenomes);
	}

	if (nchildren > NPOP - KEEPOLD * nspecies)
	{
		nchildren = NPOP - KEEPOLD * nspecies;
		listshorten<Genome*>(children, nchildren);
	}
	
	addtospecies(children, nchildren);
	
	generation++;
}
    /****************************************************************
    SampleImage
        Samples the entire image and stores the sample in a list.
        Based on width,height it randomly samples the entire image.
    Exceptions:
        None
    ****************************************************************/
    void    SampleSet::SampleImage(Matrixu*    pGrayImageMatrix,
                                   uint        numberOfSamples, 
                                   int        w,
                                   int        h,
                                   Matrixu*    pRGBImageMatrix,
                                   Matrixu*    pHSVImageMatrix,
                                   float    scaleX, 
                                   float    scaleY )
    {
        try
        {
            ASSERT_TRUE( pGrayImageMatrix != NULL || pRGBImageMatrix != NULL || pHSVImageMatrix    != NULL );
            //find the width and height based on the current scale
            int scaledWidth        = cvRound( float(w) * scaleX );
            int scaledHeight    = cvRound( float(h) * scaleY );

            int numberOfRows;    
            int numberOfColumns;
            if ( pGrayImageMatrix != NULL ) 
            {        
                numberOfRows = pGrayImageMatrix->rows() - scaledHeight - 1;
                numberOfColumns = pGrayImageMatrix->cols() - scaledWidth - 1;
            }
            else if( pRGBImageMatrix != NULL )
            {
                numberOfRows = pRGBImageMatrix->rows() - scaledHeight - 1;
                numberOfColumns = pRGBImageMatrix->cols() - scaledWidth - 1;
            }
            else
            {
                numberOfRows = pHSVImageMatrix->rows() - scaledHeight - 1;
                numberOfColumns = pHSVImageMatrix->cols() - scaledWidth - 1;
            }

            ASSERT_TRUE( numberOfSamples <= ( numberOfRows * numberOfColumns ) );

            //resize the sample list to the required number of samples
            m_sampleList.resize( numberOfSamples );

            #pragma omp for
            for ( int i = 0; i < (int)numberOfSamples; i++ )
            {
                m_sampleList[i].m_pImgGray    = pGrayImageMatrix;
                m_sampleList[i].m_col        = randint( 0, numberOfColumns );
                m_sampleList[i].m_row        = randint( 0, numberOfRows );
                m_sampleList[i].m_height    = h;
                m_sampleList[i].m_width        = w;
                m_sampleList[i].m_pImgColor = pRGBImageMatrix;
                m_sampleList[i].m_pImgHSV    = pHSVImageMatrix;
                m_sampleList[i].m_scaleX    = scaleX;
                m_sampleList[i].m_scaleY    = scaleY;
            }
        }
        EXCEPTION_CATCH_AND_ABORT( "Failed to random sample entire image for the number of samples" );
    }
int Game::room_number()
{
	//	need to improve  ending if run out of possible rooms
	n1 = randint(2, 20);
	n2 = randint(2, 20);
	n3 = randint(2, 20);
	
	if(n1==n2 || n2==n3 || n3==n1) {
		cerr << "\nRandomizer engine fail: numbers are equal";
		n1 = randint(2, 20);
		n2 = randint(2, 20);
		n3 = randint(2, 20);
	}		//need to improve rerandom if finds equal int
	
	for(int i = 0; i != curr_rooms.size(); ++i) {	// iterate trough rooms vector and check if was before
		if (n1 == curr_rooms[i])	{
			n1 = randint(2, 20);
		} else if (n2 == curr_rooms[i])	{
			n2 = randint(2, 20);
		} else if (n3 == curr_rooms[i])	{
			n3 = randint(2, 20);
		}	
		if(n1 == curr_rooms[i] && n2 == curr_rooms[i] && n3 == curr_rooms[i]) {		// simulate full curr_rooms vector // need to improve
			cerr << "\nRun out of room numbers";
			cout << "\nYou`ve found the exit!";
			return -1;
		}
		//else 	{
		//	cerr << "\nRun out of room numbers";
		//	cout << "\nYou`ve found the exit!";
		//}
		
	}
	return n1, n2, n3;
}
void test() {
    /* Field testing: SPOJ HORRIBLE */

    int n = 100000;
    vi arr(n);
    for (int i = 0; i < n; i++) {
        arr[i] = randint(-1000, 1000);
    }

    segment_tree x(arr);
    segment_tree_slow xslow(arr);

    for (int i = 0; i < 100000; i++) {
        int op = randint(0, 2);
        if (op == 0) {
            int a = randint(0, n-1),
                b = randint(a, n-1);
            assert_equal(xslow.query(a, b), x.query(a, b));
        } else if (op == 1) {
            int idx = randint(0, n-1),
                val = randint(-1000, 1000);
            x.update(idx, val);
            xslow.update(idx, val);
        } else if (op == 2) {
            int a = randint(0, n-1),
                b = randint(a, n-1),
                v = randint(-1000, 1000);

            x.range_update(a, b, v);
            xslow.range_update(a, b, v);
        }
    }
}
Beispiel #9
0
int
rate_next(iter_t *iter)
{
	if (iter->i1) {
		iter->i1 = 0;
		return (int)randint(0,3);
	} else {
		iter->i1 = 1;
		return (int)randint(5,9);
	}
}
Beispiel #10
0
word_t test_randword1(rand_t state)
{
	word_t res = 0;
    int bits = (int) randint(7, state);
	int i;

	for (i = 0; i < bits; i++)
		res |= (WORD(1) << randint(WORD_BITS, state));

	return res;
}
Beispiel #11
0
void test5() {
  const int n = 97;
  int count = 0;
  perm root(*range(n));
  int a = 0, b = 0;
  while (a == b) {
    a = randint(1, n);
    b = randint(1, n);
  }
  swap(root[a], root[b]);  
  dfs(root, -1);
}
Beispiel #12
0
const char *
response(response_t type)
{
  if (!type)
    type = randint(RES_TYPES) + 1;

  /* wait to count the totals until it's used for the first time */
  if (!response_totals[type])
    count_responses(type);

  return res[type][randint(response_totals[type])];
}
Beispiel #13
0
int getch(int h, int ch)
{
	if (randint(0,2)!=0) return ch;
	int nch;
	if (ch < 3)
		nch = ch + randint(1,2);
	else if (ch > h-4)
		nch = ch + randint(-2,0);
	else
		nch = ch + randint(-2,2);
	return nch;
}
Beispiel #14
0
int test_F_mpn_mul()
{
   mp_limb_t * int1, * int2, * product, * product2;
   mp_limb_t msl, msl2;
   int result = 1;
   
   unsigned long count;
   for (count = 0; (count < 30) && (result == 1); count++)
   {
      unsigned long limbs2 = randint(2*FLINT_FFT_LIMBS_CROSSOVER)+1;
      unsigned long limbs1 = limbs2 + randint(1000);
   
      int1 = (mp_limb_t *) malloc(sizeof(mp_limb_t)*limbs1);

      mpn_random2(int1, limbs1);
        
      unsigned long count2;
      for (count2 = 0; (count2 < 30) && (result == 1); count2++)
      {    
#if DEBUG
         printf("%ld, %ld\n",limbs1, limbs2);
#endif

         int2 = (mp_limb_t *) malloc(sizeof(mp_limb_t)*limbs2);
         product = (mp_limb_t *) malloc(sizeof(mp_limb_t)*(limbs1+limbs2));
         product2 = (mp_limb_t *) malloc(sizeof(mp_limb_t)*(limbs1+limbs2));
         
         F_mpn_clear(int2, limbs2);
         mpn_random2(int2, randint(limbs2-1)+1);
      
         msl = F_mpn_mul(product, int1, limbs1, int2, limbs2);
         
         msl2 = mpn_mul(product2, int1, limbs1, int2, limbs2);
      
         unsigned long j;
         for (j = 0; j < limbs1+limbs2 - (msl == 0); j++)
         {
            if (product[j] != product2[j]) result = 0;
         }
         
         result &= (msl == msl2);
         
         free(product2);
         free(product);
         free(int2);
      }
   
      free(int1);
   }   
   
   return result;
}
Beispiel #15
0
// Creates the starting bacteria and populates the list
void create_starting_bacteria() {
  
  int s, i;
  Strain* strain;
  
  for (s = 0; s < num_strains; s++) {
    strain = strains[s];
    for (i = 1; i <= start_population_per_strain; i++) {
      add_bacterium(strain, randint(1,grid_size), randint(1,grid_size));
    }
  }

}
Beispiel #16
0
int test_F_mpn_splitcombine_bits()
{
    mp_limb_t * int1, * int2;
    ZmodF_poly_t poly;
    int result = 1;
    
    unsigned long count;
    for (count = 0; (count < 30000) && (result == 1); count++)
    {
        unsigned long limbs = randint(300)+1;
        unsigned long bits = randint(500)+1;
        unsigned long coeff_limbs = randint(100) + (bits-1)/FLINT_BITS + 1;
        unsigned long length = (FLINT_BITS*limbs - 1)/bits + 1;
        unsigned long log_length = 0;
        while ((1L << log_length) < length) log_length++;
        
#if DEBUG
        printf("limbs = %ld, bits = %ld, coeff_limbs = %ld\n", limbs, bits, coeff_limbs);
#endif
        
        int1 = (mp_limb_t *) malloc(sizeof(mp_limb_t)*limbs);
        int2 = (mp_limb_t *) malloc(sizeof(mp_limb_t)*limbs);
        ZmodF_poly_init(poly, log_length, coeff_limbs, 0);
        
        mpn_random2(int1, limbs);
        F_mpn_FFT_split_bits(poly, int1, limbs, bits, coeff_limbs);
        F_mpn_clear(int2, limbs);
        F_mpn_FFT_combine_bits(int2, poly, bits, coeff_limbs, limbs);

#if DEBUG
        F_mpn_printx(int1, limbs); printf("\n\n");
        unsigned long i;
        for (i = 0; i < length; i++) { F_mpn_printx(poly->coeffs[i], coeff_limbs); printf("\n");}
        printf("\n");
        F_mpn_printx(int2, limbs); printf("\n\n");
#endif

        unsigned long j;
        for (j = 0; j < limbs; j++)
        {
           if (int1[j] != int2[j]) result = 0;
        }
        
        ZmodF_poly_clear(poly);
        free(int2);
        free(int1);
    }
    
    return result;
}
string randstr(int llen, int rlen, int lc, int rc){

	string res = "";
	
	int len = randint(llen, rlen);
	for (int i = 0; i < len; ++i){
	
		char ch = randint(lc, rc);
		res.push_back(ch);
		
	}
	
	return res;

}
Beispiel #18
0
char *mkalphanum(int len) {
 //returns an alphanumeric string of len length
  int size = len + 1;
  char *s = malloc(sizeof(char) * size);
  char c;
  s[size] = 0;
  for (int i = 0; i < size;i++) {
    int typeflag = randint(1);
    if (typeflag == 0)
       s[i] = randalpha();
    else
       s[i] = randint(9) + '0';
  }
  s[size] = '\0';
  return s;
}
Beispiel #19
0
bool make_decision(int n)
{
	if (n > 100 || n < 1) error("Wrong percentage");
	int t = randint(1, 100);
	if (t <= n) return true;
	else return false;
}
Beispiel #20
0
Link* Link::insert(Link* n)   // insert n before this object; return n
{
	if (n->value < 1 || n->value > system_length) error("Too low/high value in inserted link");
	if (n == 0) return this;
	if (this == 0) return n;

	while (true)
	{
		while (this->find(n) != 0) // Проверка на присутствие свободных слотов на этом уровне.
		{
			if (n->value >= system_length) n->level++;
			else n->value = randint(1, 10);
		}
		if (n->value > this->value) // Если элемент больше по значению, добавляем его после данного элемента.
		{
			if (succ) succ->prev = n;
			n->succ = succ;
			n->prev = this;
			succ = n;

			return n;
		}
		else						// Если элемент меньше по значению, вставляем его до этого элемента.
		{
			n->succ = this;           // this object comes after n
			if (prev) prev->succ = n;
			n->prev = prev;           // this object's predecessor becomes n's predecessor
			prev = n;                 // n becomes this object's predecessor

			return n;
		}
	}
}
Beispiel #21
0
static
void
try_mkdir(int dofork)
{
	void * a0 = randptr();
	int a1 = randint();
	int result, pid, status;
	char buf[128];

	snprintf(buf, sizeof(buf), "mkdir(%p, %d)",
		(a0), (a1));
	printf("%-47s", buf);

	pid = dofork ? fork() : 0;
	if (pid<0) {
		err(1, "fork");
	}
	if (pid>0) {
		waitpid(pid, &status, 0);
		return;
	}

	result = mkdir(a0, a1);
	printf(" result %d, errno %d\n", result, errno);
	if (dofork) {
		exit(0);
	}
}
Beispiel #22
0
void init(void)
{
	for(uint8_t i = 0; i < matrix_xyz_len; i++) {
		vars.xyz[i] = (xyz_t){
			.x = randint(0, LEDS_X),
			.y = randint(0, LEDS_Y),
			.z = randint(0, LEDS_Z)
		};
	}

	clear_buffer();
}
void effect(void)
{
	clear_buffer();

	for(uint8_t i = 0; i < matrix_xyz_len; i++) {
		xyz_t xyz = vars.xyz[i];

		for(uint8_t j = 0; j < 3; j++) {
			if(xyz.z + j < LEDS_Z) {
				set_led(xyz.x, xyz.y, xyz.z + j, MAX_INTENSITY);
			}
		}

		uint8_t z = xyz.z;

		z++;

		if(z >= LEDS_Z) z = 0;

		vars.xyz[i].z = z;
	}
}
Beispiel #23
0
main(int argc, char* argv[]) {
    sset h,i,j,r;
    int n,seed;
    string cmd;

    n = 1000;
    dkst F(n);
    seed = 1;
    if (argc > 1) sscanf(argv[1],"%d",&seed);
    srandom(seed);
    int vec[n+1];
    misc::genPerm(n,vec);
    for (j = 1; j <= n; j++) F.setkey(j,vec[j],vec[vec[j]]);

    for (j = 2; j <= n; j++) F.insert(j,F.root(1));
    // cout << F;

    for (i = 1; i <= 10*n; i++) {
        r = F.root(1);
        j = randint(1,n);
        F.remove(j,r);
        for (h = 1; h <= n; h++) {
            if (F.key2(h) != vec[vec[h]]) {
                cout << "bad key2 value for " << h << endl;
                cout << F;
                exit(1);
            }
        }
        r = F.root(j == 1 ? 2 : 1);
        F.insert(j,r);
        // cout << F;
    }
}
Beispiel #24
0
static
void
try_getdirentry(int dofork)
{
	int a0 = randint();
	void * a1 = randptr();
	size_t a2 = randsize();
	int result, pid, status;
	char buf[128];

	snprintf(buf, sizeof(buf), "getdirentry(%d, %p, %lu)",
		(a0), (a1), (unsigned long)(a2));
	printf("%-47s", buf);

	pid = dofork ? fork() : 0;
	if (pid<0) {
		err(1, "fork");
	}
	if (pid>0) {
		waitpid(pid, &status, 0);
		return;
	}

	result = getdirentry(a0, a1, a2);
	printf(" result %d, errno %d\n", result, errno);
	if (dofork) {
		exit(0);
	}
}
Beispiel #25
0
void placeMonster (char entityArray[MAP_SIZE][MAP_SIZE], entity entityInfo[], char mapArray[MAP_SIZE][MAP_SIZE], int roomWidth, int roomHeight, int monNumber) {
   int posx,posy;
   generatePosition(roomWidth, roomHeight, &posx, &posy);
   while ((mapArray[posx][posy]!= EMPTY_SPACE) || (entityArray[posx][posy] != NO_ENTITY)) {
      generatePosition(roomWidth, roomHeight, &posx, &posy);
   }
   char symbolChoose = randint(4); //char to save space
   char monSymbol;
   if (symbolChoose == 0) { //choose a non-unique symbol for the monster
// you wanted a unique identifier? maybe next time
      monSymbol = '#';
   } else if (symbolChoose == 1) {
      monSymbol = '&';
   } else if (symbolChoose == 2) {
      monSymbol = '$';
   } else if (symbolChoose == 3) {
      monSymbol = '+';
   } else if (symbolChoose == 4) {
      monSymbol = '*';
   }
   entityArray[posx][posy] = monSymbol; //dump all the map specific info on the entity
   entityInfo[monNumber].entityx = posx;
   entityInfo[monNumber].entityy = posy;
   entityInfo[monNumber].entitySymbol = monSymbol;
   return;
}
Beispiel #26
0
void do_grad(int* studentsInRoom, sema gradAllowedMutex, int* gradsEaten, sema roomTypeMutex, enum studentType* currentStudentType) {
    while (1) {
        sema_down(gradAllowedMutex);
        sema_down(roomTypeMutex);
        if (*currentStudentType != ugrad && *studentsInRoom < 2) {

            (*studentsInRoom) += 1;
            *currentStudentType = grad;
            sema_up(roomTypeMutex);

            (*gradsEaten) += 1;
            // 6 grads have eaten, lock out more grads until ugrads get a turn
            if (*gradsEaten == NUM_GRADS) { sema_down(gradAllowedMutex); }

            printf("grad eating...\n");
            sleep(randint());
            printf("  grad done\n");

            sema_down(roomTypeMutex);
            (*studentsInRoom) -= 1;
            if (*studentsInRoom == 0) { *currentStudentType = empty; }
            sema_up(roomTypeMutex);
        } else {
            sema_up(roomTypeMutex);
        }
    }
}
Beispiel #27
0
/* Make a password, 10-15 random letters and digits
 */
void makepass(char *s)
{
  int i;

  i = 10 + randint(6);
  make_rand_str(s, i);
}
Beispiel #28
0
	void CloudParticle::remove_neighbor(const CloudParticle*const p)
	{
		for (int i = 0; i < (int)neighbors.size();)
		{
			std::vector<CloudParticle*>::iterator iter = neighbors.begin() + i;
			if (*iter == p)
			{
				neighbors.erase(iter);
				continue;
			}
			i++;
		}

		if (effect->particles.size() <= 2)
			return;

		if (!neighbors.size())
		{
			std::map<Particle*, bool>::iterator next_iter;
			int offset;
			CloudParticle* next;
			while (true)
			{
				next_iter = effect->particles.begin();
				offset = randint((int)effect->particles.size());
				for (int j = 0; j < offset; j++)
					next_iter++;
				next = (CloudParticle*)next_iter->first;
				if ((next != this) && (next != p))
					break;
			}
			neighbors.push_back(next);
			next->add_incoming_neighbor(this);
		}
	}
int main()
try {
    srand(time(0));
    const int test_val = 75;
    while (true) {
        skip_list sl;
        for (int i = 0; i<23; ++i)
            sl.insert(randint(100));
        sl.debug_print();
        cout << "Enter value to remove: ";
        int x;
        cin >> x;
        if (x==-1) return 0;

        element* p = sl.find(x);
        sl.remove(x);
        sl.debug_print();
        cout << "\n";
    }
}
catch (exception& e) {
    cerr << "exception: " << e.what() << endl;
}
catch (...) {
    cerr << "exception\n";
}
Beispiel #30
0
/*
** gen_rand_symbol - generates random password of specified type
** INPUT:
**   char * - symbol.
**   unsigned int - symbol type.
** OUTPUT:
**   int - password length or -1 on error.
** NOTES:
**   none.
*/
int
gen_rand_symbol (char *symbol, unsigned int mode)
{
  int j = 0;
  char *str_pointer;
  int random_weight[94];
  int max_weight = 0;
  int max_weight_element_number = 0;

  for (j = 0; j <= 93; j++) random_weight[j] = 0; 
  str_pointer = symbol;
  j = 0;
/* Asign random weight in weight array if mode is present*/
  for (j = 0; j <= 93 ; j++)
     if ( ( (mode & smbl[j].type) > 0) &&
         !( (S_RS & smbl[j].type) > 0))
       random_weight[j] = 1 + randint(20000);
  j = 0;
/* Find an element with maximum weight */
  for (j = 0; j <= 93; j++)
     if (random_weight[j] > max_weight)
       {
        max_weight = random_weight[j];
        max_weight_element_number = j;
       }
/* Get password symbol */
  *str_pointer = smbl[max_weight_element_number].ch;
  max_weight = 0;
  max_weight_element_number = 0;
  return (0);
}