Exemplo n.º 1
0
/**********************************************************************
 * Hound Breath
 **********************************************************************/
static int _breath_effect(void)
{
    switch (p_ptr->current_r_idx)
    {
    case MON_LIGHT_HOUND: return GF_LITE;
    case MON_SHADOW_HOUND: return GF_DARK;
    case MON_FIRE_HOUND: return GF_FIRE;
    case MON_COLD_HOUND: return GF_COLD;
    case MON_ENERGY_HOUND: return GF_ELEC;
    case MON_AIR_HOUND: return GF_POIS;
    case MON_WATER_HOUND: return GF_ACID;
    case MON_EARTH_HOUND: return GF_SHARDS;
    case MON_VIBRATION_HOUND: return GF_SOUND;
    case MON_NEXUS_HOUND: return GF_NEXUS;
    case MON_MULTI_HUED_HOUND:
    {
        int choices[] = {GF_FIRE, GF_COLD, GF_ELEC, GF_ACID, GF_POIS, -1};
        return _random(choices);
    }
    case MON_INERTIA_HOUND: return GF_INERT;
    case MON_IMPACT_HOUND: return GF_FORCE;
    case MON_NETHER_HOUND: return GF_NETHER;
    case MON_GRAVITY_HOUND: return GF_GRAVITY;
    case MON_TIME_HOUND: return GF_TIME;
    case MON_PLASMA_HOUND: return GF_PLASMA;
    case MON_CHAOS_HOUND: return GF_CHAOS;
    case MON_HOUND_OF_TINDALOS:
    {
        int choices[] = {GF_NETHER, GF_TIME, -1};
        return _random(choices);
    }
    case MON_MANA_HOUND: return GF_MANA;
    case MON_AETHER_HOUND:
    {
        int choices[] = {GF_FIRE, 1, 
                         GF_COLD, 1,
                         GF_ELEC, 2,
                         GF_ACID, 2,
                         GF_POIS, 1,
                         GF_LITE, 2,
                         GF_DARK, 2,
                         GF_CONFUSION, 1,
                         GF_NETHER, 1,
                         GF_NEXUS, 2,
                         GF_SOUND, 3,
                         GF_SHARDS, 5,
                         GF_CHAOS, 4,
                         GF_DISENCHANT, 4,
                         GF_TIME, 3,
                         GF_INERT, 3,
                         GF_FORCE, 3,
                         GF_GRAVITY, 4,
                         GF_PLASMA, 5,
                         -1, 0};
        return _random_weights(choices);
    }
    }
    return GF_FIRE; /* ?? */
}
Exemplo n.º 2
0
Node3D::Node3D(int index, int symbol, QColor color, int size)
{
    set_index(index);
    set_coordinates(_random(), _random(), _random());
    set_size(1);
    set_marked(false);
    set_selected(false);
    set_label("");
}
Exemplo n.º 3
0
static void
gennum(U32 out[], size_t count)
{
	for (size_t i = 0; i < count; ++i) {
		out[i] = _random();
		out[i] = (out[i] << 16) | _random();
		out[i] %= 100000000U;
	}
}
Exemplo n.º 4
0
int Canvas3D::random()
{
	Nodes::ConstIterator uit = m_nodes.constBegin();
	Nodes::ConstIterator uend = m_nodes.constEnd();

	for (; uit != uend; ++uit)
		uit.value()->set_coordinates(_random(), _random(), _random());

	return 0;
}
Exemplo n.º 5
0
Arquivo: game.c Projeto: shiver/vectir
// creates some particles to show score incrememnts
void game_showScoreIncrement(int line, int increment) {
	int i;
	char buffer[5];
	Particle *first = NULL;
	Particle *current = NULL;

	for (i = 0; i < GRID_WIDTH; i++) {
		if (first == NULL) { // if we dont have any particles yet
      first = particle_createNewParticle();
      current = first;

      graphics_clear(); // clear the back buffer

      // create the texture for the increments
      // TODO: adjust for adjustable resolution
      if (!score_increment_texture) {
				sprintf(buffer, "+%d", increment);
				font_print(0, 0, buffer, NULL); // put the text into the back buffer
		    glFlush();				
				score_increment_texture = graphics_createTextureFromViewport(0, 
																																		 SCREEN_HEIGHT - 128, 
																																		 128, 128);
			}
			else {
				if (increment != previous_increment) {
					sprintf(buffer, "+%d", increment);
					font_print(0, 0, buffer, NULL); // put the text into the back buffer
		      glFlush();	
					graphics_adjustTextureFromViewport(0, SCREEN_HEIGHT - 128, 128, 128, 
																						score_increment_texture);
				}
			}
			current->texture = score_increment_texture;
    }
    else { // if we're adding to already existing
      current->next = particle_createNewParticle();
      current = current->next;
      current->texture = first->texture;
    }

		// set some initial particle states
		current->alpha = 0.8f;
		current->alpha_decay = -((_random(2) + 1) * 0.01);
		current->v_speed = -((_random(10) + 1) * 0.1);
    current->x = 20 + (GRID_BLOCK_SIZE * i);
	    current->y = (GRID_BLOCK_SIZE/2) + (GRID_BLOCK_SIZE * line);
	}

  // add to the collection
  particle_createNewCollection(first);

	previous_increment = increment;
}
Exemplo n.º 6
0
static Evas_Real
_smooth(Evas_Real x, Evas_Real y)
{
   Evas_Real res;
   res = (_random(x - 1, y - 1) + _random(x + 1, y - 1) +
        _random(x - 1, y + 1) + _random(x + 1, y + 1)) / 16;
   res += (_random(x - 1, y) + _random(x + 1, y) +
        _random(x, y - 1) + _random(x, y + 1)) / 8;
   res += _random(x, y) / 4;
   return res;
}
Exemplo n.º 7
0
static void _random(Request& r, MethodParams& params) {
	double top=params.as_double(0, "range must be expression", r);
	if(top<=0 || top>MAX_UINT)
		throw Exception(PARSER_RUNTIME,
			0,
			"top(%g) must be [1..%u]", top, MAX_UINT);
	
	r.write_no_lang(*new VInt(_random(uint(top))));
}
Exemplo n.º 8
0
void Events::adsorbIslands(int nIslands, int islandSize)
{
	for (int i = 0; i < nIslands; i++) {
		int position = static_cast<int> (floor(_random() * c::A));
		for (int j = 0; j < islandSize; j++) {
			adsorption(neigh::neigh(n, position), atomType::silicon);
		}
	}
}
Exemplo n.º 9
0
static void _gain_level(int new_level) {
    int tier = _find_tier(p_ptr->current_r_idx);
    if (tier < 0 || tier == _MAX_TIERS - 1) return;
    if (p_ptr->lev >= _tiers[tier + 1].level)
    {
        p_ptr->current_r_idx = _random(_tiers[tier+1].r_ids);
        msg_format("You have evolved into a %s.", _mon_name(p_ptr->current_r_idx));
        p_ptr->redraw |= PR_MAP;
    }
}
Exemplo n.º 10
0
void Events::execute()
{
	evolve();

newChoose:;

	double chooseEvent = _random() * rates.total;

	if (chooseEvent < rates.totalAds) {
		int index = static_cast<int> (floor(chooseEvent / rates.ads));

		adsorption(index, atomType::metal);
	}
	else if (chooseEvent < rates.totalAds + rates.totalDes) {
		chooseEvent -= rates.totalAds;
		double cumulateRates = 0;
		unsigned ei = 0, ej = 0;
      while (cumulateRates + rates.sumsofDes[ei] < chooseEvent) {
         if (ei >= c::nDesTypes) {
            goto newChoose;
         }
         cumulateRates += rates.sumsofDes[ei++];
      }
      ej = static_cast<int> (floor((chooseEvent - cumulateRates) / rates.des[ei]));
      if (ej >= eventLists._desEvents[ei].size()) {
         goto newChoose;
      }/*

		if (ei % c::nNeighCount == 0)
			_nFreeDes++;

      _nDesorbNeigh[ei % c::nNeighCount]++;*/

		desorption(eventLists._desEvents[ei][ej]);
	}
	else {
		chooseEvent -= rates.totalAds + rates.totalDes;
		double cumulateRates = 0;
		unsigned ei = 0, ej = 0;
      while (cumulateRates + rates.sumsofDiff[ei] < chooseEvent) {
         if (ei >= c::nDiffTypes) {
            goto newChoose;
         }
         cumulateRates += rates.sumsofDiff[ei++];
      }
		ej = static_cast<int> (floor((chooseEvent - cumulateRates) / rates.diff[ei]));
      if (ej >= eventLists._diffEvents[ei].size()) {
         goto newChoose;
      }
		checkDiff(ei, eventLists._diffEvents[ei][ej]);
		diffusion(eventLists._diffEvents[ei][ej]);
   }
   _nEvents++;
}
Exemplo n.º 11
0
void _oneMetropolisStep(int* config, double* delta, double beta, int m, int acstep){
    int x        = _randomInt(m);
    int y        = _randomInt(m);
    double pflip = _random();
    int dE       = 2*_getLocalEnergy(config, x, y, m);
    if (dE <= 0 || pflip < _fastPow(M_E,-beta*dE)){
//    if (dE < 0 || pflip < exp(-beta*dE)){
        config[x*m+y] *= -1;
        delta[acstep*2] = x;
        delta[acstep*2+1] = y;
    }
}
Exemplo n.º 12
0
int* generateTerrain(float peakheight, float flatness) {
  time_t start; srand(start);

  float offset = (float)SCREEN_HEIGHT/2;
  float r1 = _random(1.0, 5.0);
  float r2 = _random(1.0, 5.0);
  float r3 = _random(1.0, 5.0);
  int *yvals = (int*)malloc(SCREEN_WIDTH*sizeof(int));
  printf("r1=%f, r2=%f, r3=%f\n", r1, r2, r3);

  for (int x=0; x<SCREEN_WIDTH; x++) {
    float y;
    y  = peakheight/r1*sin((x/flatness*r1)+r1);
    y += peakheight/r2*sin((x/flatness*r2)+r2);
    y += peakheight/r3*sin((x/flatness*r3)+r3);
    y += offset;
    yvals[x] = (int)y;
  }

  return &(yvals[0]);
}
Exemplo n.º 13
0
void Events::executeDes()
{
   evolution._rates.setSums(eventLists._desEvents, eventLists._diffEvents);

	double chooseEvent = _random() * rates.totalDes;
	double cumulateRates = 0;
	int ei = 0, ej = 0;
	while (cumulateRates + rates.sumsofDes[ei] < chooseEvent)
		cumulateRates += rates.sumsofDes[ei++];
	ej = static_cast<int> (floor((chooseEvent - cumulateRates) / rates.des[ei]));

	desorption(eventLists._desEvents[ei][ej]);
}
Exemplo n.º 14
0
	operation random_operator()
	{
		const double r = _random();
//		if( r < 0.05 )
//			return plus;
//		else if( r < 0.10 )
//			return plusequals;
//		else 
		if( r < 0.50 )
			return times;
		else 
			return timesequals;
	}
Exemplo n.º 15
0
//获取随机的Pet服装不包括挂件
DressCon DressSelector::GetPetRandomDress(int bmale)
{
	DressCon res;
	for(int i=0;i<H3DI::PET_BODYPART_NUM;++i)
	{
		size_t s=m_pet_dresslink[i][bmale].size();
		idRandom2 _random(GetTickCount());
		int rand_idx=_random.RandomInt(s);
		DressCon* pCon=&(m_pet_dresslink[i][bmale]);
		if(!pCon->empty())
			res.push_back(pCon->at(rand_idx));
	}

	return res;
}
Exemplo n.º 16
0
//获取随机的人物挂件
DressCon DressSelector::GetActorRandomLink(int bmale)
{
	DressCon res;
	for(int i=H3DI::BODYPART_NUM-1;i<ACTOR_ITEM_NUM;++i)
	{
		size_t s=m_actor_dresslink[i][bmale].size();
		idRandom2 _random(GetTickCount());
		int rand_idx=_random.RandomInt(s);
		DressCon* pCon=&(m_actor_dresslink[i][bmale]);
		if(!pCon->empty())
			res.push_back(pCon->at(rand_idx));
	}

	return res;
}
	void FDFireflyIceTaskSteps::next(std::function<void()> invocation)
	{
		//    FDFireflyDeviceLogDebug(@"queing next step %@", NSStringFromSelector(selector));

		fireflyIce->executor->feedWatchdog(shared_from_this());

		_invocation = invocation;
		_invocationId = _random();

		//    FDFireflyDeviceLogDebug(@"setup ping 0x%08x %@ %@", _invocationId, NSStringFromClass([self class]), NSStringFromSelector(_invocation.selector));

		FDBinary binary = FDBinary();
		binary.putUInt32(_invocationId);
		std::vector<uint8_t> data = binary.dataValue();
		fireflyIce->coder->sendPing(channel, data);
	}
Exemplo n.º 18
0
//获取随机的人物服装不包括挂件
DressCon DressSelector::GetActorRandomDress(int bmale)
{
	DressCon res;
	for(int i=0;i<H3DI::BODYPART_NUM-1;++i)
	{
		size_t s=m_actor_dresslink[i][bmale].size();
		idRandom2 _random(GetTickCount());
		int rand_idx=_random.RandomInt(s);
		DressCon* pCon=&(m_actor_dresslink[i][bmale]);
		if(!pCon->empty())
			res.push_back(pCon->at(rand_idx));
		//std::copy(pCon->begin(),pCon->end(),std::back_inserter(res));
	}
	
	return res;
}
Exemplo n.º 19
0
//获取随机的Pet挂件
DressCon DressSelector::GetPetRandomLink(int bmale)
{
	DressCon res;
	for(int i=10;i<13;++i) //宠物是10-13
	{
		int idx=GetPetAdoArrayIdx(i);
		size_t s=m_pet_dresslink[idx][bmale].size();
		idRandom2 _random(GetTickCount());
		int rand_idx=_random.RandomInt(s);
		DressCon* pCon=&(m_pet_dresslink[idx][bmale]);
		if(!pCon->empty())
			res.push_back(pCon->at(rand_idx));
	}

	return res;
}
Exemplo n.º 20
0
static void _crypt(Request& r, MethodParams& params) {
	const char* password=params.as_string(0, "password must be string").cstr();
	const char* maybe_bodyless_salt=params.as_string(1, "salt must be string").cstr();

	size_t prefix_size=calc_prefix_size(maybe_bodyless_salt);
	const char* normal_salt;
	char normalize_buf[MAX_STRING];
	if(prefix_size==strlen(maybe_bodyless_salt)) { // bodyless?
		strncpy(normalize_buf, maybe_bodyless_salt, MAX_STRING-MAX_SALT-1);
		char *cur=normalize_buf+strlen(normalize_buf);
		// sould add up MAX_SALT random chars
		static unsigned char itoa64[] =         /* 0 ... 63 => ASCII - 64 */
		"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
		for(int i=0; i<MAX_SALT; i++)
			*cur++=itoa64[_random(64)];
		*cur=0;
		normal_salt=normalize_buf;
	} else
		normal_salt=maybe_bodyless_salt;

	/* FreeBSD style MD5 string 
	*/
	if(strncmp(normal_salt, PA_MD5PW_ID, PA_MD5PW_IDLEN) == 0) {
		const size_t sample_size=120;
		char *sample_buf=new(PointerFreeGC) char[sample_size];
		pa_MD5Encode((const unsigned char *)password,
				(const unsigned char *)normal_salt, sample_buf, sample_size);
		String sample(sample_buf);
		r.write_pass_lang(sample);
	} else {
#ifdef HAVE_CRYPT
		const char* static_sample_buf=crypt(password, normal_salt);
		if(!static_sample_buf  // nothing generated
			|| !static_sample_buf[0] // generated nothing
			|| strncmp(static_sample_buf, normal_salt, prefix_size)!=0) // salt prefix not preserved
			throw Exception(PARSER_RUNTIME,
				0,
				"crypt on this platform does not support '%.*s' salt prefix", prefix_size, normal_salt);
		
		r.write_pass_lang(String(pa_strdup(static_sample_buf)));
#else
		throw Exception(PARSER_RUNTIME,
			0,
			"salt must start with '" PA_MD5PW_ID "'");
#endif
	}
}
Exemplo n.º 21
0
	void perturb_emissions( double amount=0.2 )
	{
		assert(amount <= 1.0); assert(amount >= 0.0);
		typedef typename Algo::probability_type P;
		typedef LogspaceDouble<P> logspace_t;

		const size_t N = num_states(*_model);
		const size_t S = num_symbols(*_model);

		for( size_t state=0; state < N; ++state)
		{
			if( _model->is_silent(state) ) continue;
			for( size_t symbol=0; symbol<S; ++symbol )
			{
				const P orig = logspace_t(_model->e(state, symbol), true);

				const P random = _random();

				const P perturbed =
					orig * (1-amount)
					+ random * amount;

				_model->SetEmissionProbability(state,
											   _model->get_symbol(symbol),
											   perturbed); // accepts probability in real space

			}
		}

		_model->normalize_emissions();
		
#ifndef NO_TESTS
		tests::test_emissions_valid_pdf<Algo>(*_model);
#endif //NO_TESTS	
		
	}
Exemplo n.º 22
0
	double random01()
	{
		return _random();
	}
Exemplo n.º 23
0
//0~10 会出现0~9  10个随机值
unsigned int _random_d(unsigned int nMax, unsigned int nMin)
{
	//if (nMax == nMin) return nMax;
	return _random(nMax-1, nMin);
}
Exemplo n.º 24
0
	std::string next() {
		std::stringstream out;
		out << static_cast<long long>(_random());
		return out.str();
	}
Exemplo n.º 25
0
unsigned Random::operator()(unsigned result) {
  return config.random ? _random() : result;
}
Exemplo n.º 26
0
    void init(long seed, Geom::Rect const &tile, Geom::Point const &freq, bool stitch,
        bool fractalnoise, int octaves)
    {
        // setup random number generator
        _setupSeed(seed);

        // set values
        _tile = tile;
        _baseFreq = freq;
        _stitchTiles = stitch;
        _fractalnoise = fractalnoise;
        _octaves = octaves;

        int i;
        for (int k = 0; k < 4; ++k) {
            for (i = 0; i < BSize; ++i) {
                _latticeSelector[i] = i;

                _gradient[i][k][0] = static_cast<double>(_random() % (BSize*2) - BSize) / BSize;
                _gradient[i][k][1] = static_cast<double>(_random() % (BSize*2) - BSize) / BSize;

                // normalize gradient
                double s = hypot(_gradient[i][k][0], _gradient[i][k][1]);
                _gradient[i][k][0] /= s;
                _gradient[i][k][1] /= s;
            }
        }
        while (--i) {
            // shuffle lattice selectors
            int j = _random() % BSize;
            std::swap(_latticeSelector[i], _latticeSelector[j]);
        }

        // fill out the remaining part of the gradient
        for (i = 0; i < BSize + 2; ++i)
        {
            _latticeSelector[BSize + i] = _latticeSelector[i];

            for(int k = 0; k < 4; ++k) {
                _gradient[BSize + i][k][0] = _gradient[i][k][0];
                _gradient[BSize + i][k][1] = _gradient[i][k][1];
            }
        }

        // When stitching tiled turbulence, the frequencies must be adjusted
        // so that the tile borders will be continuous.
        if (_stitchTiles) {
            if (_baseFreq[Geom::X] != 0.0)
            {
                double freq = _baseFreq[Geom::X];
                double lo = floor(_tile.width() * freq) / _tile.width();
                double hi = ceil(_tile.width() * freq) / _tile.width();
                _baseFreq[Geom::X] = freq / lo < hi / freq ? lo : hi;
            }
            if (_baseFreq[Geom::Y] != 0.0)
            {
                double freq = _baseFreq[Geom::Y];
                double lo = floor(_tile.height() * freq) / _tile.height();
                double hi = ceil(_tile.height() * freq) / _tile.height();
                _baseFreq[Geom::Y] = freq / lo < hi / freq ? lo : hi;
            }

            _wrapw = _tile.width() * _baseFreq[Geom::X] + 0.5;
            _wraph = _tile.height() * _baseFreq[Geom::Y] + 0.5;
            _wrapx = _tile.left() * _baseFreq[Geom::X] + PerlinOffset + _wrapw;
            _wrapy = _tile.top() * _baseFreq[Geom::Y] + PerlinOffset + _wraph;
        }
        _inited = true;
    }