コード例 #1
0
ファイル: LinearGenerator.cpp プロジェクト: Kavenon/jimp-2014
int LinearGenerator::toGenerate() {

  setSeed(myRand());
  while((getSeed() > getMaxValue()) || (getSeed() < getMinValue()))
    setSeed(myRand());
  print(std::cout);
  return getSeed();
}
コード例 #2
0
ファイル: Rand.cpp プロジェクト: BackupTheBerlios/escript-svn
/**
 * Random returns a pseudo-random real number uniformly distributed
 * between 0.0 and 1.0.
 */
Rand::floatType Rand::random() {
	const intType Q = MODULUS / MULTIPLIER;
	const intType R = MODULUS % MULTIPLIER;
	intType t = MULTIPLIER * ( getSeed() % Q) - R * (getSeed()  / Q);
	if (t > 0)
		setSeed(t);
	else
		setSeed(t + MODULUS);
	return ( static_cast<floatType>(getSeed()) / MODULUS);
}
コード例 #3
0
int DefaultGenerator::toGenerate() {

  srand(getSeed());
  setSeed(getMinValue() + rand() % getMaxValue());
  while((getSeed() > getMaxValue()) || (getSeed() < getMinValue()))
    setSeed(getMinValue() + rand() % getMaxValue());
  print(cout);
  return getSeed();

}
コード例 #4
0
std::string RippleAddress::humanSeed1751() const
{
    switch (nVersion) {
    case VER_NONE:
		throw std::runtime_error("unset source - humanSeed1751");

    case VER_FAMILY_SEED:
		{
			std::string strHuman;
			std::string strLittle;
			std::string strBig;
			uint128 uSeed	= getSeed();

			strLittle.assign(uSeed.begin(), uSeed.end());

			strBig.assign(strLittle.rbegin(), strLittle.rend());

			key2eng(strHuman, strBig);

			return strHuman;
		}

    default:
		throw std::runtime_error(str(boost::format("bad source: %d") % int(nVersion)));
    }
}
コード例 #5
0
void CPointMesh::start()
{
	if (m_ps->m_normal == NULL) {
		m_ps->computeNormal(10);
		m_ps->adjustNormal(10);
	}
	m_ps->constructKdTree();
	m_links.clear();
	m_faces.clear();
	m_fontPoints.clear();

	m_links.resize(m_ps->getPointSize());

	size_t seed = getSeed(0);
	m_fontPoints.push_back(seed);
	size_t handand = 0;
	while (m_fontPoints.size() != 0) {
		seed = m_fontPoints.front();
		m_fontPoints.pop_front();
		externPoint(seed);
		handand ++;
		if (handand % 100 == 0)
			m_pView->draw();
	}
	m_links.clear();
//	cout<< m_faces.size()<<endl;
}
コード例 #6
0
bool RNGLinearCong::operator==(IRNG& rhs){
    if(getType()==rhs.getType()&&getSeed()==rhs.getSeed()){
        return true;
    }else{
        return false;
    }
}
コード例 #7
0
ファイル: FileRNG.cpp プロジェクト: FernandoDucha/TheRngLab
bool FileRNG::operator==(IRNG& rhs) {
    if(getType()==rhs.getType()&&getSeed()==rhs.getSeed()){
        return true;
    }else{
        return false;
    }
}
コード例 #8
0
ファイル: problem3-2.c プロジェクト: gyifan/csci_backup
void napping(int t){
	unsigned int seed = getSeed();

#ifdef DEBUG
	unsigned long test = rand_r(&seed)*1000000*t;
	printf("rand is %lu\n",test);
#endif /* DEBUG */

	// Cast to unsigned long to make it able to be divided by RAND_MAX
	// otherwise, it will be 0 all the time. 
	//
	// Uses microsecond to give more random selection between 0 and t.
	unsigned int sleepTime = (t*1000000*(unsigned long)rand_r(&seed))/RAND_MAX;

#ifdef DEBUG
	printf("sleepTime is %u\n", sleepTime);
	printf("seed is %u\n", seed);
	printf("Rand_Max is %d\n", (int)RAND_MAX);
#endif /* DEBUG */

	// Test if usleep takes usec more than 1000000.	
	if(usleep(sleepTime)){
		perror("usleep failed");
		exit(-1);
	}
}
コード例 #9
0
ファイル: gardensStudent.cpp プロジェクト: theconnor/mcgill
vector<Seed> Flower::getSeeds(unsigned int k) const {
	vector<Seed> seeds;
	
	for(int i = 0; i < k; i++)	
		seeds.push_back(getSeed(i));

	return seeds; }
コード例 #10
0
void TurbulenceModule::write (utils::OutStream &s) const
{
	s.writeDouble (mPower);
	s.writeInt (getRoughness());
	s.writeInt (getSeed());
	s.writeDouble (getFrequency());
	s.writeInt (getQuality());
}
コード例 #11
0
ファイル: bigfixedpoint.cpp プロジェクト: RealGrep/QMentat
BigFixedPoint BigFixedPoint::random(const BigFixedPoint& n)
{
    if (!isSeeded) {
        r.seed(getSeed());
        isSeeded = true;
    }
    mpz_class num = r.get_z_range(n.number+1);
    return BigFixedPoint(num, n.getDecimalPlaces());
}
コード例 #12
0
ファイル: mersenne-twister.C プロジェクト: Singular/LELA
void MersenneTwister::setSeed (uint32 seed) 
{
	if (seed == 0)
		seed = getSeed ();

	//
	// We initialize _state[0..(N-1)] via the generator
	//
	//   x_new = (69069 * x_old) mod 2^32
	//
	// from Line 15 of Table 1, p. 106, Sec. 3.3.4 of Knuth's
	// _The Art of Computer Programming_, Volume 2, 3rd ed.
	//
	// Notes (SJC): I do not know what the initial state requirements
	// of the Mersenne Twister are, but it seems this seeding generator
	// could be better.  It achieves the maximum period for its modulus
	// (2^30) iff x_initial is odd (p. 20-21, Sec. 3.2.1.2, Knuth); if
	// x_initial can be even, you have sequences like 0, 0, 0, ...;
	// 2^31, 2^31, 2^31, ...; 2^30, 2^30, 2^30, ...; 2^29, 2^29 + 2^31,
	// 2^29, 2^29 + 2^31, ..., etc. so I force seed to be odd below.
	//
	// Even if x_initial is odd, if x_initial is 1 mod 4 then
	//
	//   the          lowest bit of x is always 1,
	//   the  next-to-lowest bit of x is always 0,
	//   the 2nd-from-lowest bit of x alternates      ... 0 1 0 1 0 1 0 1 ... ,
	//   the 3rd-from-lowest bit of x 4-cycles        ... 0 1 1 0 0 1 1 0 ... ,
	//   the 4th-from-lowest bit of x has the 8-cycle ... 0 0 0 1 1 1 1 0 ... ,
	//    ...
	//
	// and if x_initial is 3 mod 4 then
	//
	//   the          lowest bit of x is always 1,
	//   the  next-to-lowest bit of x is always 1,
	//   the 2nd-from-lowest bit of x alternates      ... 0 1 0 1 0 1 0 1 ... ,
	//   the 3rd-from-lowest bit of x 4-cycles        ... 0 0 1 1 0 0 1 1 ... ,
	//   the 4th-from-lowest bit of x has the 8-cycle ... 0 0 1 1 1 1 0 0 ... ,
	//    ...
	//
	// The generator's potency (min. s>=0 with (69069-1)^s = 0 mod 2^32) is
	// 16, which seems to be alright by p. 25, Sec. 3.2.1.3 of Knuth.  It
	// also does well in the dimension 2..5 spectral tests, but it could be
	// better in dimension 6 (Line 15, Table 1, p. 106, Sec. 3.3.4, Knuth).
	//
	// Note that the random number user does not see the values generated
	// here directly since reloadMT() will always munge them first, so maybe
	// none of all of this matters.  In fact, the seed values made here could
	// even be extra-special desirable if the Mersenne Twister theory says
	// so-- that's why the only change I made is to restrict to odd seeds.
	//

	register uint32 x = (seed | 1U) & 0xFFFFFFFFU;
	register std::vector<uint32>::iterator s = _state.begin ();
	register int j;

	for (_left = 0, *s++ = x, j = N; --j; *s++ = (x *= 69069U) & 0xFFFFFFFFU) ;
}
コード例 #13
0
ファイル: Generator2.cpp プロジェクト: yqbk/CPP
// ---------------------------------------------------------
// ---------------------------------------------------------
Generator2::Generator2(int iPoczatek, int iKoniec, unsigned long seed, unsigned long mnoznik, unsigned long add, unsigned long modul, string strNazwaGeneratora)
{
    this->setPoczatek(iPoczatek);
    this->setKoniec(iKoniec);
    this->setNazwa(strNazwaGeneratora);
    this->setSeed(seed);
    this->mnoznik = mnoznik;
    this->add = add;
    this->modul = modul;
    this->x = getSeed(); 
}
コード例 #14
0
int IsdnTest::NObjRndPatternGenSettings::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    typedef Domain::NamedObject QMocSuperClass;
    _id = QMocSuperClass::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    
#ifndef QT_NO_PROPERTIES
     if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< int*>(_v) = getSeed(); break;
        case 1: *reinterpret_cast< int*>(_v) = getChangeBytesChancePercent(); break;
        case 2: *reinterpret_cast< int*>(_v) = getMaxChangeBits(); break;
        case 3: *reinterpret_cast< int*>(_v) = getCutBytesChancePercent(); break;
        case 4: *reinterpret_cast< int*>(_v) = getMaxCutBytes(); break;
        case 5: *reinterpret_cast< int*>(_v) = getAddBytesChancePercent(); break;
        case 6: *reinterpret_cast< int*>(_v) = getMaxAddBytes(); break;
        }
        _id -= 7;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setSeed(*reinterpret_cast< int*>(_v)); break;
        case 1: setChangeBytesChancePercent(*reinterpret_cast< int*>(_v)); break;
        case 2: setMaxChangeBits(*reinterpret_cast< int*>(_v)); break;
        case 3: setCutBytesChancePercent(*reinterpret_cast< int*>(_v)); break;
        case 4: setMaxCutBytes(*reinterpret_cast< int*>(_v)); break;
        case 5: setAddBytesChancePercent(*reinterpret_cast< int*>(_v)); break;
        case 6: setMaxAddBytes(*reinterpret_cast< int*>(_v)); break;
        }
        _id -= 7;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 7;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
コード例 #15
0
Variant GillespieIntegrator::getItem(const std::string& key) const
{
    if (key == "seed")
    {
        return Variant(getSeed());
    }
    else if(key == "rand")
    {
        // cheating
        GillespieIntegrator *pthis = const_cast<GillespieIntegrator*>(this);
        return Variant(pthis->urand());
    }

    std::string err = "invalid key: \"";
    err += key;
    err += "\"";
    throw std::invalid_argument(err);
}
コード例 #16
0
// place the code into the table
void codeTable(unsigned char *table)
{
int i;
int seedData[99];
long	seed = 0;
int index;
int count = 0;
Str255 estr = ENCRYPT_STR;

//if (isPressed(0x3a)) return;

// get the seed data

index = (16+16*33)*4;
for (i=0; i<33; i++)
	{
	seedData[i*3] = table[index+i*33*33*4];		// cyan
	seedData[i*3+1] = table[index+i*33*33*4+1];	// magenta
	seedData[i*3+2] = table[index+i*33*33*4+2];	// yellow
	}
	
seed = getSeed(seedData,99);

// write twelve bytes of data

// a = -128, b = -128
index = (0+0*33)*4;
for (i=0; i<16; i++)
	{
	setBit(&table[index+i*33*33*4],estr,&count,&seed);
	setBit(&table[index+i*33*33*4+1],estr,&count,&seed);
	setBit(&table[index+i*33*33*4+2],estr,&count,&seed);
	}
	
// a = 128, b = 128	
index = (32+32*33)*4;
for (i=0; i<16; i++)
	{
	setBit(&table[index+i*33*33*4],estr,&count,&seed);
	setBit(&table[index+i*33*33*4+1],estr,&count,&seed);
	setBit(&table[index+i*33*33*4+2],estr,&count,&seed);
	}
}
コード例 #17
0
/**
 * Sequentially simulate each period.
 *
 * @param withSeeds True if stored seeds should be used to reset the RNG at the
 *        beginning of each period.
 */
void StatisticsSimulation::simulatePeriods(bool withSeeds) {
	GetRNGstate();
	#pragma omp parallel num_threads(lNThreads)
	{
		#pragma omp for schedule(dynamic, 1)
		for (unsigned int thread = 0; thread < lNThreads; ++thread) {
			// Run epoch simulation for each period
			LOGS(Priority::DEBUG) << "simulate with theta: " << rParameters().transpose();
			for (int m = 0; m < lpData->observationCount() - 1; ++m) {
				if (withSeeds) {
					setSeed(lSeeds[m]);
				} else {
					getSeed(lSeeds[m]);
				}
				simulatePeriod(thread, m);
			}
		}
	}
	PutRNGstate();
}
コード例 #18
0
ファイル: CvRandom.cpp プロジェクト: Isabelxxx/Civ4-K-Mod
unsigned short CvRandom::get(unsigned short usNum, const TCHAR* pszLog)
{
	if (pszLog != NULL)
	{
		if (GC.getLogging() && GC.getRandLogging())
		{
			if (GC.getGameINLINE().getTurnSlice() > 0)
			{
				TCHAR szOut[1024];
				sprintf(szOut, "Rand = %ul / %hu (%s) on %d\n", getSeed(), usNum, pszLog, GC.getGameINLINE().getTurnSlice());
				gDLL->messageControlLog(szOut);
			}
		}
	}

	m_ulRandomSeed = ((RANDOM_A * m_ulRandomSeed) + RANDOM_C);

	unsigned short us = ((unsigned short)((((m_ulRandomSeed >> RANDOM_SHIFT) & MAX_UNSIGNED_SHORT) * ((unsigned long)usNum)) / (MAX_UNSIGNED_SHORT + 1)));

	return us;
}
コード例 #19
0
ファイル: fm_map.cpp プロジェクト: Selat/freeminer
s16 ServerMap::updateBlockHumidity(ServerEnvironment *env, v3POS p, MapBlock *block, std::map<v3POS, s16> * cache) {
	auto bp = getNodeBlockPos(p);
	auto gametime = env->getGameTime();
	if (block) {
		if (gametime < block->humidity_last_update)
			return block->humidity + myrand_range(0, 1);
	} else if (!cache) {
		block = getBlockNoCreateNoEx(bp, true);
	}
	if (cache && cache->count(bp))
		return cache->at(bp) + myrand_range(0, 1);

	auto value = m_emerge->biomemgr->calcBlockHumidity(p, getSeed(),
	             env->getTimeOfDayF(), gametime * env->getTimeOfDaySpeed(), env->m_use_weather);

	if(block) {
		block->humidity = value;
		block->humidity_last_update = env->m_use_weather ? gametime + 30 : -1;
	}
	if (cache)
		(*cache)[bp] = value;
	return value + myrand_range(0, 1);
}
コード例 #20
0
ファイル: Generator.cpp プロジェクト: Kavenon/jimp-2014
void Generator::print(std::ostream& out){
  out << getSeed() << "   ";
}
コード例 #21
0
ファイル: LinearGenerator.cpp プロジェクト: Kavenon/jimp-2014
int LinearGenerator::myRand(){
  // ax + b
  // where x = seed, a = variableA, b = variableB
  return getMinValue() + (getVariableA() * getSeed() + getVariableB()) % getMaxValue();
}
コード例 #22
0
ファイル: CvRandom.cpp プロジェクト: Jheral/Civ5Comps
unsigned short CvRandom::get(unsigned short usNum, const char* pszLog)
{
	recordCallStack();
	m_ulCallCount++;

	unsigned long ulNewSeed = ((RANDOM_A * m_ulRandomSeed) + RANDOM_C);
	unsigned short us = ((unsigned short)((((ulNewSeed >> RANDOM_SHIFT) & MAX_UNSIGNED_SHORT) * ((unsigned long)usNum)) / (MAX_UNSIGNED_SHORT + 1)));

	if(GC.getLogging())
	{
		int iRandLogging = GC.getRandLogging();
		if(iRandLogging > 0 && (m_bSynchronous || (iRandLogging & RAND_LOGGING_ASYNCHRONOUS_FLAG) != 0))
		{
#if !defined(FINAL_RELEASE)
			if(!gDLL->IsGameCoreThread() && gDLL->IsGameCoreExecuting() && m_bSynchronous)
			{
				CvAssertMsg(0, "App side is accessing the synchronous random number generator while the game core is running.");
			}
#endif
			CvGame& kGame = GC.getGame();
			if(kGame.getTurnSlice() > 0 || ((iRandLogging & RAND_LOGGING_PREGAME_FLAG) != 0))
			{
				FILogFile* pLog = LOGFILEMGR.GetLog("RandCalls.csv", FILogFile::kDontTimeStamp, "Game Turn, Turn Slice, Range, Value, Seed, Instance, Type, Location\n");
				if(pLog)
				{
					char szOut[1024] = {0};
					sprintf_s(szOut, "%d, %d, %u, %u, %u, %8x, %s, %s\n", kGame.getGameTurn(), kGame.getTurnSlice(), (uint)usNum, (uint)us, getSeed(), (uint)this, m_bSynchronous?"sync":"async", (pszLog != NULL)?pszLog:"Unknown");
					pLog->Msg(szOut);

#if !defined(FINAL_RELEASE)
					if((iRandLogging & RAND_LOGGING_CALLSTACK_FLAG) != 0)
					{
#ifdef _DEBUG
						if(m_bExtendedCallStackDebugging)
						{
							// Use the callstack from the extended callstack debugging system
							const FCallStack& callStack = m_kCallStacks.back();
							std::string stackTrace = callStack.toString(true, 6);
							pLog->Msg(stackTrace.c_str());
						}
						else
#endif
						{
#ifdef WIN32
							// Get callstack directly
							FCallStack callStack;
							FDebugHelper::GetInstance().GetCallStack(&callStack, 0, 8);
							std::string stackTrace = callStack.toString(true, 6);
							pLog->Msg(stackTrace.c_str());
#endif
						}
					}
#endif
				}
			}
		}
	}

	m_ulRandomSeed = ulNewSeed;
	return us;
}
コード例 #23
0
RenderableParticleBunchPtr RenderableParticleStage::createBunch(std::size_t cycleIndex)
{
	return RenderableParticleBunchPtr(new RenderableParticleBunch(
		cycleIndex, getSeed(cycleIndex), _stageDef, _viewRotation, _direction, _entityColour));
}
コード例 #24
0
ファイル: random.cpp プロジェクト: Marvin182/mr
std::mt19937& getGenerator() {
	static std::mt19937 generator{getSeed()};
	return generator;
}
コード例 #25
0
void Continuous2DSignalTerrain::onReSeed(unsigned int seed) {
	if(signal!=NULL){
		signal->seed(getSeed());
	}
}
コード例 #26
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void SegmentGrains::execute()
{
  setErrorCondition(0);
  VoxelDataContainer* m = getVoxelDataContainer();
  std::stringstream ss;
  if(NULL == m)
  {
    setErrorCondition(-1);
    ss << " DataContainer was NULL";
    addErrorMessage(getHumanLabel(), ss.str(), -1);
    return;
  }

  size_t udims[3] =
  { 0, 0, 0 };
  m->getDimensions(udims);
#if (CMP_SIZEOF_SIZE_T == 4)
  typedef int32_t DimType;
#else
  typedef int64_t DimType;
#endif
  DimType dims[3] =
  { static_cast<DimType>(udims[0]), static_cast<DimType>(udims[1]), static_cast<DimType>(udims[2]), };

  size_t gnum = 1;
  int seed = 0;
  int neighbor;
  bool good = 0;
  DimType col, row, plane;
  size_t size = 0;
  size_t initialVoxelsListSize = 1000;
  std::vector<int> voxelslist(initialVoxelsListSize, -1);
  DimType neighpoints[6];
  neighpoints[0] = -(dims[0] * dims[1]);
  neighpoints[1] = -dims[0];
  neighpoints[2] = -1;
  neighpoints[3] = 1;
  neighpoints[4] = dims[0];
  neighpoints[5] = (dims[0] * dims[1]);

  // Burn volume with tight orientation tolerance to simulate simultaneous growth/aglomeration
  while (seed >= 0)
  {
    seed = getSeed(gnum);
    if(seed >= 0)
    {
      size = 0;
      voxelslist[size] = seed;
      size++;
      for (size_t j = 0; j < size; ++j)
      {
        // Get the current Voxel
        size_t currentpoint = voxelslist[j];
        // Figure out the Row, Col & Plane the voxel is located in
        col = currentpoint % dims[0];
        row = (currentpoint / dims[0]) % dims[1];
        plane = currentpoint / (dims[0] * dims[1]);

        // Now loop over its 6 neighbors
        for (int i = 0; i < 6; i++)
        {
          good = true;
          neighbor = currentpoint + neighpoints[i];
          // Make sure we have a valid neighbor taking into account the edges of the volume
          if(i == 0 && plane == 0) good = false;
          if(i == 5 && plane == (dims[2] - 1)) good = false;
          if(i == 1 && row == 0) good = false;
          if(i == 4 && row == (dims[1] - 1)) good = false;
          if(i == 2 && col == 0) good = false;
          if(i == 3 && col == (dims[0] - 1)) good = false;

          if(good == true)
          {
            // We got a good voxel to check so check to see if it can be grouped with this point
            if(determineGrouping(currentpoint, neighbor, gnum) == true)
            {
              // The voxel can be grouped with this voxel so add it to the list of voxels for this grain
              voxelslist[size] = neighbor;
              // Increment the size of the list which affects the "j" loop
              size++;
              // Sanity check the size of the voxelslist vector. If it is not large enough, double the size of the vector
              if(size >= voxelslist.size())
              {
                voxelslist.resize(size + size, -1); // The resize is a hit but the doubling mitigates the penalty somewhat
              }
            }
          }
        }
      }
      voxelslist.clear();
      voxelslist.resize(initialVoxelsListSize, -1);
      gnum++;
      ss.str("");
      ss << "Total Grains: " << gnum;
      if(gnum%100 == 0) notifyStatusMessage(ss.str());
      if (getCancel() == true)
      {
        setErrorCondition(-1);
        break;
      }
    }
  }


  // If there is an error set this to something negative and also set a message
 notifyStatusMessage("Completed");
}