void Randomizer::timeSeed() { seed( time(0) ); }
void CurveAgent::reset(const SteerLib::AgentInitialConditions & initialConditions, SteerLib::EngineInterface * engineInfo) { // compute the "old" bounding box of the agent before it is reset. its OK that it will be invalid if the agent was previously disabled // because the value is not used in that case. Util::AxisAlignedBox oldBounds(__position.x-_radius, __position.x+_radius, 0.0f, 0.0f, __position.z-_radius, __position.z+_radius); // initialize the agent based on the initial conditions __startPosition = initialConditions.position; __position = initialConditions.position; _forward = initialConditions.direction; _radius = initialConditions.radius; _velocity = initialConditions.speed * Util::normalize(initialConditions.direction); // Find random agent color if (initialConditions.colorSet) agentColor = initialConditions.color; else { std::random_device seed; std::default_random_engine generator(seed()); std::uniform_real_distribution<float> distribution(0.0f, 0.8f); agentColor = Util::Color(distribution(generator), distribution(generator), distribution(generator)); } // compute the "new" bounding box of the agent Util::AxisAlignedBox newBounds(__position.x-_radius, __position.x+_radius, 0.0f, 0.0f, __position.z-_radius, __position.z+_radius); if (!_enabled) { // if the agent was not enabled, then it does not already exist in the database, so add it. gSpatialDatabase->addObject( this, newBounds); } else { // if the agent was enabled, then the agent already existed in the database, so update it instead of adding it. gSpatialDatabase->updateObject( this, oldBounds, newBounds); } _enabled = true; if (initialConditions.goals.size() == 0) { throw Util::GenericException("No goals were specified!\n"); } // iterate over the sequence of goals specified by the initial conditions. for (unsigned int i=0; i<initialConditions.goals.size(); i++) { if (initialConditions.goals[i].goalType == SteerLib::GOAL_TYPE_SEEK_STATIC_TARGET) { _goalQueue.push_back(initialConditions.goals[i]); if (initialConditions.goals[i].targetIsRandom) { // if the goal is random, we must randomly generate the goal. _goalQueue.back().targetLocation = gSpatialDatabase->randomPositionWithoutCollisions(1.0f, true); } } else { throw Util::GenericException("Unsupported goal type; CurveAgent only supports GOAL_TYPE_SEEK_STATIC_TARGET."); } } // Add control points to curve std::vector<Util::CurvePoint> controlPoints; Util::Vector startTangent(0.f, 0.f, 0.f); controlPoints.push_back(Util::CurvePoint(__position, startTangent, 0.f)); for (int i = 0; i < _goalQueue.size(); i++) { controlPoints.push_back(Util::CurvePoint(_goalQueue[i].targetLocation, _goalQueue[i].targetTangent, _goalQueue[i].targetTime)); } curve.addControlPoints(controlPoints); assert(_forward.length()!=0.0f); assert(_goalQueue.size() != 0); assert(_radius != 0.0f); }
std::size_t class_2_hasher::hash(const class_2&v) { std::size_t seed(0); combine(seed, v.prop_0()); return seed; }
/** * Constructs a new @c subtract_with_carry_engine and seeds * it with @c value. */ BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(subtract_with_carry_engine, IntType, value) { seed(value); }
/** * Constructs a new @c subtract_with_carry_engine and seeds * it with values from a range. first is updated to point * one past the last value consumed. If there are not * enough elements in the range to fill the entire state of * the generator, throws @c std::invalid_argument. */ template<class It> subtract_with_carry_engine(It& first, It last) { seed(first,last); }
MTRand::MTRand() { seed(); }
bool RarVolume::DecryptRar3Prepare(const uint8 salt[8]) { WString wstr(*m_password); int len = wstr.Length(); if (len == 0) return false; CharBuffer seed(len * 2 + 8); for (int i = 0; i < len; i++) { wchar_t ch = wstr[i]; seed[i * 2] = ch & 0xFF; seed[i * 2 + 1] = (ch & 0xFF00) >> 8; } memcpy(seed + len * 2, salt, 8); debug("seed: %s", *Util::FormatBuffer((const char*)seed, seed.Size())); #ifdef HAVE_OPENSSL EVP_MD_CTX* context = EVP_MD_CTX_create(); if (!EVP_DigestInit(context, EVP_sha1())) { EVP_MD_CTX_destroy(context); return false; } #elif defined(HAVE_NETTLE) sha1_ctx context; sha1_init(&context); #else return false; #endif uint8 digest[20]; const int rounds = 0x40000; for (int i = 0; i < rounds; i++) { #ifdef HAVE_OPENSSL EVP_DigestUpdate(context, *seed, seed.Size()); #elif defined(HAVE_NETTLE) sha1_update(&context, seed.Size(), (const uint8_t*)*seed); #endif uint8 buf[3]; buf[0] = (uint8)i; buf[1] = (uint8)(i >> 8); buf[2] = (uint8)(i >> 16); #ifdef HAVE_OPENSSL EVP_DigestUpdate(context, buf, sizeof(buf)); #elif defined(HAVE_NETTLE) sha1_update(&context, sizeof(buf), buf); #endif if (i % (rounds / 16) == 0) { #ifdef HAVE_OPENSSL EVP_MD_CTX* ivContext = EVP_MD_CTX_create(); EVP_MD_CTX_copy(ivContext, context); EVP_DigestFinal(ivContext, digest, nullptr); EVP_MD_CTX_destroy(ivContext); #elif defined(HAVE_NETTLE) sha1_ctx ivContext = context; sha1_digest(&ivContext, sizeof(digest), digest); #endif m_decryptIV[i / (rounds / 16)] = digest[sizeof(digest) - 1]; } } #ifdef HAVE_OPENSSL EVP_DigestFinal(context, digest, nullptr); EVP_MD_CTX_destroy(context); #elif defined(HAVE_NETTLE) sha1_digest(&context, sizeof(digest), digest); #endif debug("digest: %s", *Util::FormatBuffer((const char*)digest, sizeof(digest))); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { m_decryptKey[i * 4 + j] = digest[i * 4 + 3 - j]; } } debug("key: %s", *Util::FormatBuffer((const char*)m_decryptKey, sizeof(m_decryptKey))); debug("iv: %s", *Util::FormatBuffer((const char*)m_decryptIV, sizeof(m_decryptIV))); return true; }
void AutoSeededRandomPool::Reseed(bool blocking, unsigned int seedSize) { SecByteBlock seed(seedSize); OS_GenerateRandomBlock(blocking, seed, seedSize); Put(seed, seedSize); }
std::size_t nef_polyhedron_hasher::hash(const nef_polyhedron& v) { std::size_t seed(0); combine(seed, v.polygons()); return seed; }
void Math::randomize() { OS::Time time = OS::get_singleton()->get_time(); seed(OS::get_singleton()->get_ticks_usec()*(time.hour+1)*(time.min+1)*(time.sec+1)*rand()); /* *OS::get_singleton()->get_time().sec); // windows doesn't have get_time(), returns always 0 */ }
std::size_t helper_configuration_hasher::hash(const helper_configuration& v) { std::size_t seed(0); combine(seed, hash_std_unordered_map_std_string_std_string(v.helper_families())); return seed; }
explicit Xorshift64Star(uint64 _seed = 1) { seed(_seed); }
returnValue Constraint::setUnitBackwardSeed( ){ uint run1; returnValue returnvalue; const uint N = grid.getNumPoints(); // BOUNDARY CONSTRAINTS: // --------------------- if( boundary_constraint->getNC() != 0 ){ BlockMatrix seed( 1, 1 ); seed.setIdentity( 0, 0, boundary_constraint->getNC() ); returnvalue = boundary_constraint->setBackwardSeed( &seed, 1 ); if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue); } // COUPLED PATH CONSTRAINTS: // ------------------------- if( coupled_path_constraint->getNC() != 0 ){ BlockMatrix seed( 1, 1 ); seed.setIdentity( 0, 0, coupled_path_constraint->getNC() ); returnvalue = coupled_path_constraint->setBackwardSeed( &seed, 1 ); if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue); } // PATH CONSTRAINTS: // ----------------- if( path_constraint->getNC() != 0 ){ BlockMatrix seed( 1, N ); for( run1 = 0; run1 < N; run1++ ) seed.setIdentity( 0, run1, path_constraint->getDim(run1) ); returnvalue = path_constraint->setBackwardSeed( &seed, 1 ); if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue); } // ALGEBRAIC CONSISTENCY CONSTRAINTS: // ---------------------------------- if( algebraic_consistency_constraint->getNC() != 0 ){ BlockMatrix seed( 1, N ); for( run1 = 0; run1 < N; run1++ ) seed.setIdentity( 0, run1, algebraic_consistency_constraint->getDim(run1) ); returnvalue = algebraic_consistency_constraint->setBackwardSeed( &seed, 1 ); if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue); } // POINT CONSTRAINTS: // ------------------ if( point_constraints != 0 ){ for( run1 = 0; run1 < grid.getNumPoints(); run1++ ){ if( point_constraints[run1] != 0 ){ BlockMatrix seed( 1, 1 ); seed.setIdentity( 0, 0, point_constraints[run1]->getNC() ); returnvalue = point_constraints[run1]->setBackwardSeed( &seed, 1 ); if( returnvalue != SUCCESSFUL_RETURN ) return ACADOERROR(returnvalue); } } } return SUCCESSFUL_RETURN; }
void XnesAlgo::runEvolution() { Eigen::MatrixXf expCovMat(m_numGenes,m_numGenes); int startGeneration = 0; char statfile[64]; char inFilename[128]; char outFilename[128]; char bestOutFilename[128]; int bestGeneration = -1; int bestFitness = -1; // Set the seed setSeed(m_rngSeed); // Initialise the individual and the covariance matrix initialise(); // Check whether to recover a previous evolution sprintf(statfile,"S%d.fit", seed()); // Check if the file exists DataChunk statTest(QString("stattest"),Qt::blue,2000,false); if (statTest.loadRawData(QString(statfile),0)) { startGeneration = statTest.getIndex(); sprintf(inFilename, "S%dG%d.gen", (seed()), startGeneration); Logger::info("Recovering from startGeneration: " + QString::number(startGeneration)); Logger::info(QString("Loading file: ") + inFilename); QFile inData(inFilename); if (inData.open(QFile::ReadOnly)) { QTextStream in(&inData); bool loaded = m_individual->loadGen(in); // Check possible errors during the loading operation if (!loaded) { Logger::error("Error in the loading of the genotype"); } // Check the consistency of the genotype (i.e., the number of genes) if (m_individual->getLength() != m_numGenes) { Logger::error("Wrong genotype length!"); } // Load the covariance matrix char covMatFilename[64]; sprintf(covMatFilename, "S%dG%d.cvm", (seed()), startGeneration); QFile covMatData(covMatFilename); if (covMatData.open(QFile::ReadOnly)) { QTextStream covMatInput(&covMatData); for (int i = 0; i < m_numGenes; i++) { for (int j = 0; j < m_numGenes; j++) { QString str; covMatInput >> str; bool ok = false; float elem = str.toFloat(&ok); if (!ok || (covMatInput.status() != QTextStream::Ok)) { Logger::error("Error in the loading of the covariance matrix"); } m_covMat(i,j) = elem; expCovMat(i,j) = 0.0; } } covMatData.close(); }
std::size_t class_1_hasher::hash(const class_1& v) { std::size_t seed(0); combine(seed, v.an_attribute()); return seed; }
/** Constructor with explicit scalar seed value given. */ Crappy( const uint32_t & iseed ) : super(false) { seed(iseed); }
MTRand::MTRand( uint32 *const bigSeed, const uint32 seedLength ) { seed(bigSeed,seedLength); }
/** Constructor with explicit vector seed value given. */ Crappy( const SeedVector & vseed ) : super(false) { seed(vseed); }
void VoronoiSeedsGenerator::generateSeeds( std::vector<Seed>& listOfSeeds ) { /* * In order to retain the current number of seeds by subdivision of the * grid, we use a bi-dimensional array. */ int** nbSeedsBySub = new int* [m_nbOfHeightSubdivisions]; for (int i = 0; i < m_nbOfHeightSubdivisions; i++) { nbSeedsBySub[i] = new int[m_nbOfWidthSubdivisions]; for (int j = 0; j < m_nbOfWidthSubdivisions; j++) { nbSeedsBySub[i][j] = 0; } } /* * So as to retain the repartition of the inserted seeds, we need to allocate another array. * This one is dynamically allocated since it will be necessary to use it as an argument * for a function. */ std::vector<Seed>** seedsBySub = new std::vector<Seed>* [m_nbOfHeightSubdivisions]; for (int i = 0; i < m_nbOfHeightSubdivisions; i++) { seedsBySub[i] = new std::vector<Seed> [m_nbOfWidthSubdivisions]; } /* * Initializing the random generator which is going to be used in order to * generate the seeds. */ std::random_device randomDevice; std::mt19937 generator(randomDevice()); std::normal_distribution<float> widthDistrib(m_width/2.0, m_width/5.0); std::normal_distribution<float> heightDistrib(m_height/2.0, m_height/5.0); /* * Main loop of the function in which the seeds are generated. * On top of that, in order to ease the implementation of the "Whittaker * step", the seeds have to be sorted according to their distance to the * center of the map. * So as to do so, the seeds are sorted by "insertion" in a temporary list, * and then pushed back in the given vector. */ std::list<Seed> tmpList; int currentNbOfSeeds = 0; while (currentNbOfSeeds < m_nbOfSeeds) { float wPosition = widthDistrib(generator); float hPosition = heightDistrib(generator); /* * Testing if the subdivision which is going to contain the new seed * is "full". */ int widthID = (int)(floor(wPosition/m_width*m_nbOfWidthSubdivisions)); int heightID = (int)(floor(hPosition/m_height*m_nbOfHeightSubdivisions)); if ( (widthID >= 0) && (widthID < m_nbOfWidthSubdivisions) && (heightID >=0) && (heightID < m_nbOfHeightSubdivisions) ) { if (nbSeedsBySub[heightID][widthID] < m_maxNbOfSeedsBySubdivision) { Seed seed(wPosition, hPosition); /* * Inserting only if the new seed is at a minimal distance * of the other ones previously inserted. */ if (isMinDistVerified(seedsBySub, widthID, heightID, seed)) { insertIntoList(tmpList, seed); currentNbOfSeeds++; nbSeedsBySub[heightID][widthID]++; seedsBySub[heightID][widthID].push_back(seed); } } } } /* * Freeing the allocated memory zone related to seeds' repartition. */ for (int i = 0; i < m_nbOfHeightSubdivisions; i++) { seedsBySub[i]->clear(); delete [] seedsBySub[i]; delete[] nbSeedsBySub[i]; } delete [] seedsBySub; delete[] nbSeedsBySub; /* * Finally, we just have to insert the content of the list into the * given vector. */ for ( auto iterator = tmpList.begin(); iterator != tmpList.end(); iterator++ ) { listOfSeeds.push_back(*iterator); } }
std::size_t integer_hasher::hash(const integer& v) { std::size_t seed(0); combine(seed, v.value()); return seed; }
/** * Constructs a new @c subtract_with_carry_engine and seeds * it with the default seed. */ subtract_with_carry_engine() { seed(); }
void Random::seed() { seed(0); }
/** * Constructs a new @c subtract_with_carry_engine and seeds * it with values produced by @c seq.generate(). */ BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(subtract_with_carry_engine, SeedSeq, seq) { seed(seq); }
NT2_CORE_RANDOM_DECL rng_settings::rng_settings() : generator_(mt19937stream()) { seed(0); }
/** Seeds the generator with the default seed. */ void seed() { seed(default_seed); }
NT2_CORE_RANDOM_DECL rng_settings::rng_settings(randstream_* g,int s) : generator_(g) { seed(s); }
template<class It> inversive_congruential(It& first, It last) { seed(first, last); }
NT2_CORE_RANDOM_DECL rng_settings::rng_settings(rng_settings const& s) { generator_ = s.generator_; seed(s.seed_); };
MTRand::MTRand( const uint32& oneSeed ) { seed(oneSeed); }
//! Seed the generator using the current time in microseconds inline void time_seed() { seed( graphlab::timer::usec_of_day() ); }