当前位置: 首页>>代码示例>>C++>>正文


C++ mt19937::seed方法代码示例

本文整理汇总了C++中std::mt19937::seed方法的典型用法代码示例。如果您正苦于以下问题:C++ mt19937::seed方法的具体用法?C++ mt19937::seed怎么用?C++ mt19937::seed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::mt19937的用法示例。


在下文中一共展示了mt19937::seed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: math_randomseed

int math_randomseed(lua_State *L){
	switch (lua_gettop(L)){
		case 0:{
			intgen.seed(ndrng());
			break;
		}
		case 1:{
			DWORD seed_value = luaL_checkint(L, 1);
			intgen.seed(seed_value);
			break;
		}
		default: return luaL_error(L, "math_randomseed: wrong number of arguments");
	}
	return 0;
}
开发者ID:Karlan88,项目名称:xray,代码行数:15,代码来源:script_additional_libs.cpp

示例2: main

int main(int argc, char **argv) {
    // Number of random expressions to test.
    const int count = 1000;
    // Depth of the randomly generated expression trees.
    const int depth = 5;
    // Number of samples to test the generated expressions for.
    const int samples = 3;

    // We want different fuzz tests every time, to increase coverage.
    // We also report the seed to enable reproducing failures.
    int fuzz_seed = argc > 1 ? atoi(argv[1]) : time(nullptr);
    rng.seed(fuzz_seed);
    std::cout << "Simplify fuzz test seed: " << fuzz_seed << std::endl;

    int max_fuzz_vector_width = 4;

    for (int i = 0; i < fuzz_type_count; i++) {
        Type T = fuzz_types[i];
        for (int w = 1; w < max_fuzz_vector_width; w *= 2) {
            Type VT = T.with_lanes(w);
            for (int n = 0; n < count; n++) {
                // Generate a random expr...
                Expr test = random_expr(VT, depth);
                if (!test_expression(test, samples)) {
                    return -1;
                }
            }
        }
    }
    std::cout << "Success!" << std::endl;
    return 0;
}
开发者ID:bleibig,项目名称:Halide,代码行数:32,代码来源:fuzz_simplify.cpp

示例3: getDummyLoopClock

double getDummyLoopClock(size_t n, size_t bitLen)
{
	uint64_t ret = 0;
	Xbyak::util::Clock clk;
#ifdef USE_C11
	g_rg.seed(0);
	std::uniform_int_distribution<uint64_t> dist(0, (1ULL << bitLen) - 1);
#else
	XorShift128 r;
	const uint64_t mask = (1ULL << bitLen) - 1;
#endif
	const int lp = 5;
	for (int i = 0; i < lp; i++) {
		clk.begin();
		for (size_t i = 0; i < n; i++) {
#ifdef USE_C11
			uint64_t v = dist(g_rg);
#else
			uint64_t v = r.get64();
			v += r.get() >> 5;
			v &= mask;
#endif
			ret += v;
		}
		clk.end();
	}
	printf("(%llx)", (long long)ret);
	return clk.getClock() / double(n) / lp;
}
开发者ID:GuXipeng,项目名称:opti,代码行数:29,代码来源:rank_test.cpp

示例4: init

void init(dynamo::Simulation& Sim, const double density)
{
  RNG.seed(std::random_device()());
  Sim.ranGenerator.seed(std::random_device()());
  Sim.dynamics = dynamo::shared_ptr<dynamo::Dynamics>(new dynamo::DynGravity(&Sim, dynamo::Vector(0,-1,0)));
  Sim.BCs = dynamo::shared_ptr<dynamo::BoundaryCondition>(new dynamo::BCNone(&Sim));
  Sim.ptrScheduler = dynamo::shared_ptr<dynamo::SNeighbourList>(new dynamo::SNeighbourList(&Sim, new dynamo::FELCBT()));
  Sim.primaryCellSize = dynamo::Vector(52,52,52);

  Sim.addSpecies(dynamo::shared_ptr<dynamo::Species>(new dynamo::SpPoint(&Sim, new dynamo::IDRangeRange(0, 0), 1.0, "Bulk", 0)));
  Sim.addSpecies(dynamo::shared_ptr<dynamo::Species>(new dynamo::SpFixedCollider(&Sim, new dynamo::IDRangeRange(1, 8), "FixedColliders", 1)));

  Sim.interactions.push_back(dynamo::shared_ptr<dynamo::Interaction>(new dynamo::IHardSphere(&Sim, 1.0, 1, new dynamo::IDPairRangeAll(), "Bulk")));
  
  Sim.locals.push_back(dynamo::shared_ptr<dynamo::Local>(new dynamo::LWall(&Sim, 1.0, 1.0, dynamo::Vector(0,1,0), dynamo::Vector(0,-2.67753263802375e+01,0), "GroundPlate", new dynamo::IDRangeAll(&Sim))));
  
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector(0, 4, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector(0.6, 1, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector(-1.51, 1, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector(-2.51, 1.5, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector(-3.51, 2, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector(-3.51, 3.5, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector(1.6, 2, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector(2, 3.5, 0), dynamo::Vector(0,0,0), Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector(-0.75, 0.5, 0), dynamo::Vector(0,0,0), Sim.particles.size()));

  Sim.ensemble = dynamo::Ensemble::loadEnsemble(Sim);
}
开发者ID:BigMacchia,项目名称:DynamO,代码行数:28,代码来源:static_spheres_test.cpp

示例5: runTest

void runTest()
{
  dynamo::Simulation Sim;

  RNG.seed(std::random_device()());
  Sim.ranGenerator.seed(std::random_device()());

  Sim.dynamics = dynamo::shared_ptr<dynamo::Dynamics>(new dynamo::DynNewtonian(&Sim));
  Sim.BCs = dynamo::shared_ptr<dynamo::BoundaryCondition>(new dynamo::BCPeriodic(&Sim));
  Sim.ptrScheduler = dynamo::shared_ptr<dynamo::Scheduler>(new Scheduler(&Sim, new Sorter()));
  Sim.primaryCellSize = dynamo::Vector(11,11,11);
  Sim.interactions.push_back(dynamo::shared_ptr<dynamo::Interaction>(new dynamo::IHardSphere(&Sim, 1.0, 1.0, new dynamo::IDPairRangeAll(), "Bulk")));
  Sim.addSpecies(dynamo::shared_ptr<dynamo::Species>(new dynamo::SpPoint(&Sim, new dynamo::IDRangeAll(&Sim), 1.0, "Bulk", 0)));

  Sim.particles.push_back(dynamo::Particle(dynamo::Vector{0.1,0,0}, dynamo::Vector{0,0,0}, Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector{1.1,0,0}, dynamo::Vector{1,0,0}, Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector{3.1,0,0}, dynamo::Vector{0,0,0}, Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector{5.1,0,0}, dynamo::Vector{0,0,0}, Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector{7.1,0,0}, dynamo::Vector{0,0,0}, Sim.particles.size()));
  Sim.particles.push_back(dynamo::Particle(dynamo::Vector{9.1,0,0}, dynamo::Vector{0,0,0}, Sim.particles.size()));

  Sim.ensemble = dynamo::Ensemble::loadEnsemble(Sim);
  Sim.endEventCount = 1000;
  Sim.addOutputPlugin("Misc");
  Sim.initialise();
  while (Sim.runSimulationStep()) {}  

  //Grab the output plugins
  dynamo::OPMisc& opMisc = *Sim.getOutputPlugin<dynamo::OPMisc>();

  //Check the mean free time is roughly what is expected
  double MFT = opMisc.getMFT();
  BOOST_CHECK_CLOSE(MFT, 3, 0.000001);
  BOOST_CHECK_MESSAGE(Sim.checkSystem() <= 1, "There are more than one invalid states in the final configuration");
}
开发者ID:BigMacchia,项目名称:DynamO,代码行数:35,代码来源:scheduler_sorter_test.cpp

示例6: main

int main(int argc, char *argv[]) {
  const int test_size = 4096 * 2;
  std::normal_distribution<float> dist(0.5f, 0.5f);
  rng.seed(0);
  float *r_values = nullptr;
  float *ret = nullptr;
  float *ret2 = nullptr;
  double sum = 0.0f;
  std::function<float()> rnd = std::bind(dist, rng);

  r_values = static_cast<float*>(_mm_malloc(sizeof(float) * test_size, 32));

  ret = static_cast<float*>(_mm_malloc(sizeof(float) * test_size, 32));
  ret2 = static_cast<float*>(_mm_malloc(sizeof(float) * test_size, 32));

  if (!(r_values && ret && ret2))
    goto exit;

  std::generate_n(r_values, test_size, rnd);
  for (int i = 0; i < 100000; ++i) {
    polynomial(ret, r_values, test_size);
    // polynomial(ret2, ret, test_size);
    sum = std::accumulate(ret, ret + test_size, sum);
  }
  std::cout << sum << std::endl;


exit:
  _mm_free(r_values);
  _mm_free(ret);
  _mm_free(ret2);
}
开发者ID:khegeman,项目名称:curlnoise_simd,代码行数:32,代码来源:poly_intrinsic.cpp

示例7: seeds

 /**
  * Create and seed the RNG
  */
 RandomGenerator() {
     std::random_device rd;
     std::mt19937::result_type random_data[std::mt19937::state_size];
     std::generate(std::begin(random_data), std::end(random_data), std::ref(rd));
     std::seed_seq seeds(std::begin(random_data), std::end(random_data));
     _mt.seed(seeds);
 }
开发者ID:JeremyPouyet,项目名称:cpp-gaf,代码行数:10,代码来源:RandomGenerator.hpp

示例8: SeedRNG

INLINE void SeedRNG()
{
	if (!s_rngSeeded)
	{
		s_randomNumberGenerator.seed((unsigned long)getMSTime());
		s_rngSeeded = true;
	}
}
开发者ID:BARBAROSS,项目名称:X-ShieldProject,代码行数:8,代码来源:globals.cpp

示例9: init

void init(v8::Local<v8::Object> target)
{
    gen.seed(static_cast<unsigned long>(
                 std::chrono::high_resolution_clock::now().time_since_epoch().count()));

    target->Set(Nan::New("rand").ToLocalChecked(),
                Nan::New<v8::FunctionTemplate>(rand)->GetFunction());
    target->Set(Nan::New("srand").ToLocalChecked(),
                Nan::New<v8::FunctionTemplate>(srand)->GetFunction());
}
开发者ID:mtojo,项目名称:node-mt19937,代码行数:10,代码来源:mt19937.cpp

示例10: randfloat

float randfloat()
{
	if (!init_rand)
	{
		device.seed(time(0));
		init_rand = true;
	}
	
	return (float)distribution(device);
}
开发者ID:cyclohexanamine,项目名称:shipbrain,代码行数:10,代码来源:neural.cpp

示例11:

			void 
			initialize(
				uint32_t seed
				)
			{
				TRACE_MESSAGE(TRACE_LEVEL_VERBOSE, "+sola::component::random::initialize");

				SERIALIZE_CALL(std::recursive_mutex, __random_lock);

				std::srand((uint32_t) std::time(NULL));

				if(seed == GENERATE_RANDOM_SEED) {
					__random_generator.seed(rand());
				} else {
					__random_generator.seed(seed);
				}
				__random_initialized = true;

				TRACE_MESSAGE(TRACE_LEVEL_VERBOSE, "-sola::component::random::initialize");
			}
开发者ID:AlekNS,项目名称:skironscrapper,代码行数:20,代码来源:random.cpp

示例12: RandomSeed

/**
 * Set the random seed used by the random functions (Random() and RandInt()).
 * The seed is casted to a 32-bit integer before being given to the random
 * number generator, but a size_t is taken as a parameter for API consistency.
 *
 * @param seed Seed for the random number generator.
 */
inline void RandomSeed(const size_t seed)
{
  randGen.seed((uint32_t) seed);
  srand((unsigned int) seed);
#if ARMA_VERSION_MAJOR > 3 || \
    (ARMA_VERSION_MAJOR == 3 && ARMA_VERSION_MINOR >= 930)
  // Armadillo >= 3.930 has its own random number generator internally that we
  // need to set the seed for also.
  arma::arma_rng::set_seed(seed);
#endif
}
开发者ID:Andrew-He,项目名称:mlpack,代码行数:18,代码来源:random.hpp

示例13: GameMain

int GameMain()
{
	s_rng.seed(1729);

	TestConstructors();
	TestMembers();
	TestNonMembers();
	TestOperators();

	Sleep(1000);
	return 0;
}
开发者ID:Innabus,项目名称:Innabus,代码行数:12,代码来源:Mtx4x4_Basic.cpp

示例14: randint

int randint(int min, int max)
{
	if (!init_rand)
	{
		device.seed(time(0));
		init_rand = true;
	}	
	
	if (min>max) return 0;
	std::uniform_int_distribution<int> uni(min, max);
	return uni(device);
}
开发者ID:cyclohexanamine,项目名称:shipbrain,代码行数:12,代码来源:neural.cpp

示例15: main

int main(){
    const int seed=3,n=100;
    const double tol=std::numeric_limits<float>::min();
    std::mt19937 mt;
    mt.seed(seed);
    float x[n];
    for (int i=0; i<n; i++) x[i]=moare_random(9)*1.0f;
    int j=0;
    for(int i=0;i<n;i++)    j+=abs(x[i])<tol;
    std::cout<< j << std::endl;
    return 0;
}
开发者ID:CCJY,项目名称:coliru,代码行数:12,代码来源:main.cpp


注:本文中的std::mt19937::seed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。