本文整理汇总了C++中std::default_random_engine::seed方法的典型用法代码示例。如果您正苦于以下问题:C++ default_random_engine::seed方法的具体用法?C++ default_random_engine::seed怎么用?C++ default_random_engine::seed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::default_random_engine
的用法示例。
在下文中一共展示了default_random_engine::seed方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RandomNum
/***********************************************************
* Generate a random number between 0 and 1.
****/
double RandomNum(bool reseed) {
static bool firstTime = true;
static std::default_random_engine gen;
static std::uniform_real_distribution<double> unif(0.0, 1.0);
if (firstTime || reseed) {
std::random_device rd;
gen.seed(rd());
firstTime = false;
}
return unif(gen);
}
示例2:
Vertex::Vertex()
{
myWeight = 1;
parent = 0;
isDraggedAlong = false;
isAbsorbed = false;
noOfChild = 0;
ExtraWeight = 0;
myRealCommunity = -1;
gen.seed(QTime::currentTime().msec());
}
示例3: getOperation
TEST_P(DequeTest, TestCorrectOperations) {
std::uniform_int_distribution <int> getOperation(0, 5);
generator.seed(5);
std::deque <int> stldeq;
mydeque <int> mydeq;
for(size_t i = 0; i < GetParam(); ++i) {
Operations thisOper = static_cast<Operations> (getOperation(generator));
switch(thisOper) {
case PUSH_BACK: {
int tmpelem = dist(generator);
mydeq.push_back(tmpelem);
stldeq.push_back(tmpelem);
}
break;
case PUSH_FRONT: {
int tmpelem = dist(generator);
mydeq.push_back(tmpelem);
stldeq.push_back(tmpelem);
}
break;
case POP_BACK: {
if(stldeq.size()) {
mydeq.pop_back();
stldeq.pop_back();
}
}
break;
case POP_FRONT: {
if(stldeq.size()) {
mydeq.pop_front();
stldeq.pop_front();
}
}
break;
case SIZE_EQUAL: {
int size_stl = stldeq.end() - stldeq.begin();
int size_my = mydeq.end() - mydeq.begin();
ASSERT_EQ(size_stl, size_my);
}
break;
case EQUAL: {
ASSERT_TRUE(std::equal(mydeq.begin(), mydeq.end(), stldeq.begin()));
}
break;
default: ASSERT_TRUE(false);
break;
}
}
SUCCEED();
}
示例4: genRandomVelocity
Vector2 Ball::genRandomVelocity() const
{
Vector2 vec;
static std::default_random_engine engine;
engine.seed(time(nullptr));
static std::bernoulli_distribution distribution;
vec.setX(distribution(engine) ? 1 : -1);
vec.setY(distribution(engine) ? 1 : -1);
return vec;
}
示例5: doInit
void doInit()
{
mutex.lock();
printf("Connecting with game server\n");
Network::connect(port.getName(), SERVER_NAME);
myLife=6;
randengine.seed(0);
mutex.unlock();
}
示例6: InitRandom
void InitRandom() {
Clock clock;
TimeStamp now;
clock.CurrentTime(&now);
uint64_t seed = (static_cast<uint64_t>(now.MicroSeconds()) << 32) +
static_cast<uint64_t>(getpid());
#ifdef HAVE_RANDOM
generator_.seed(seed);
#elif defined(_WIN32)
srand(seed);
#else
srandom(seed);
#endif
}
示例7: randomInteger
int randomInteger(int max, int min) {
if (max == min)
return max;
orAssertGreaterThan(max, min);
if (!engineIsSeeded) {
engine.seed(std::chrono::system_clock::now().time_since_epoch().count());
engineIsSeeded = true;
}
int range = max - min;
auto elem = distributions.find(range);
if (elem == distributions.end()) {
distributions[range] = std::uniform_int_distribution<int>(0, range);
return distributions[range](engine) + min;
} else {
return std::get<1>(*elem)(engine) + min;
}
}
示例8: GetRandomEggTextureFilepath
std::string EasterEggFactory::GetRandomEggTextureFilepath()
{
// MAKE SURE THAT THE RANDOM NUMBER GENERATOR HAS BEEN INITIALIZED.
static bool randomNumberGeneratorInitialized = false;
static std::default_random_engine randomNumberGenerator;
if (!randomNumberGeneratorInitialized)
{
// Initialize the random number generator with a seed based on the current time.
unsigned long seed = static_cast<unsigned long>(std::chrono::system_clock::now().time_since_epoch().count());
randomNumberGenerator.seed(seed);
randomNumberGeneratorInitialized = true;
}
// SELECT A RANDOM EGG TEXTURE.
// An random index is selected that is restricted to the valid range of indices
// into the egg texture array.
unsigned int randomEggTextureIndex = ( randomNumberGenerator() % EGG_TEXTURE_FILEPATHS.size() );
return EGG_TEXTURE_FILEPATHS[randomEggTextureIndex];
}
示例9: main
int main(int argc, char** argv) {
// Google tools initialization
google::InitGoogleLogging(argv[0]);
google::SetUsageMessage(
"A Connect Four game based on Minimax with Alpha-Beta prunning.");
google::ParseCommandLineFlags(&argc, &argv, true);
// Random seed
PRNG.seed(FLAGS_seed);
// Show used options
LOG(INFO) << "-o " << FLAGS_o;
LOG(INFO) << "-rows " << FLAGS_rows;
LOG(INFO) << "-cols " << FLAGS_cols;
LOG(INFO) << "-seed " << FLAGS_seed;
LOG(INFO) << "-ai " << FLAGS_ai;
LOG(INFO) << "-max_depth " << FLAGS_max_depth;
LOG(INFO) << "-wh " << FLAGS_wh;
LOG(INFO) << "-random " << FLAGS_random;
// Play!
Game game;
game.Play();
return 0;
}
示例10: main
int main(int argc, char* argv[])
{
fstream myfile, gradfile;
gradfile.open("gradsRNN.txt", ios::trunc | ios::out);
double dt = 1.0;
double tau = 30.0;
int PHASE=LEARNING;
int RANDW = 0;
if (argc > 1)
for (int nn=1; nn < argc; nn++)
{
if (strcmp(argv[nn], "test") == 0) { PHASE = TESTING; cout << "Test mode. " << endl; }
if (strcmp(argv[nn], "RANDW") == 0) { RANDW = 1; } // Randomize weights. Only useful for 'test' mode.
if (strcmp(argv[nn], "METHOD") == 0) { METHOD = argv[nn+1]; }
if (strcmp(argv[nn], "MODULTYPE") == 0) { MODULTYPE = argv[nn+1]; }
if (strcmp(argv[nn], "SQUARING") == 0) { SQUARING = atoi(argv[nn+1]); }
if (strcmp(argv[nn], "DEBUG") == 0) { DEBUG = atoi(argv[nn+1]); }
if (strcmp(argv[nn], "G") == 0) { G = atof(argv[nn+1]); }
if (strcmp(argv[nn], "ETA") == 0) { ETA = atof(argv[nn+1]); }
if (strcmp(argv[nn], "TAU") == 0) { tau = atof(argv[nn+1]); }
//if (strcmp(argv[nn], "INPUTMULT") == 0) { INPUTMULT = atof(argv[nn+1]); }
if (strcmp(argv[nn], "ALPHAMODUL") == 0) { ALPHAMODUL = atof(argv[nn+1]); }
if (strcmp(argv[nn], "PROBAMODUL") == 0) { PROBAMODUL = atof(argv[nn+1]); }
if (strcmp(argv[nn], "ALPHATRACE") == 0) { ALPHATRACE = atof(argv[nn+1]); }
if (strcmp(argv[nn], "ALPHATRACEEXC") == 0) { ALPHATRACEEXC = atof(argv[nn+1]); }
if (strcmp(argv[nn], "RNGSEED") == 0) { RNGSEED = atof(argv[nn+1]); }
if (strcmp(argv[nn], "MAXDW") == 0) { MAXDW = atof(argv[nn+1]); }
}
string SUFFIX = "_G" + to_string(G) + "_MAXDW" + to_string(MAXDW) + "_ETA" + to_string(ETA) + "_ALPHAMODUL" + to_string(ALPHAMODUL) + "_PROBAMODUL" + to_string(PROBAMODUL) + "_SQUARING" +to_string(SQUARING) + "_MODULTYPE-" + MODULTYPE +
"_ALPHATRACE" + to_string(ALPHATRACE) + "_METHOD-" + METHOD + "_ATRACEEXC" + to_string(ALPHATRACEEXC) + "_TAU" + to_string(tau) +
//"_INPUTMULT" +to_string(INPUTMULT) +
"_RNGSEED" +
to_string(RNGSEED);
cout << SUFFIX << endl;
myrng.seed(RNGSEED);
srand(RNGSEED);
int trialtype;
int NBTRIALS = 507;
int TRIALTIME = 300;
int TIMEINPUT = 100;
int TIMEMODUL = 210;
int TIMERESP = 200;
VectorXi modulmarker(NBNEUR); modulmarker.setZero();
if (PHASE == TESTING)
{
NBTRIALS = 20*NBPATTERNS;
//NBTRIALS = 40*NBPATTERNS;
//TRIALTIME = 1500;
}
MatrixXd dJ(NBNEUR, NBNEUR); dJ.setZero();
MatrixXd win(NBNEUR, NBIN); win.setRandom(); //win.row(0).setZero(); // Input weights are uniformly chosen between -1 and 1, except possibly for output cell (not even necessary). No plasticity for input weights.
win *= .2;
MatrixXd J(NBNEUR, NBNEUR);
cout << Uniform(myrng) << endl;
randJ(J); // Randomize recurrent weight matrix, according to the Sompolinsky method (Gaussian(0,1), divided by sqrt(ProbaConn*N) and multiplied by G - see definition of randJ() below).
// If in the TESTING mode, read the weights from a previously saved file:
if (PHASE == TESTING){
if (RANDW == 0){
//readWeights(J, "J.dat");
//readWeights(win, "win.dat");
readWeights(J, "J" + SUFFIX + ".dat");
readWeights(win, "win" + SUFFIX + ".dat"); // win doesn't change over time.
}
else cout << "Using random weights." << endl;
}
//cout << J(0,0) << " " << win(1,1) << endl;
VectorXd meanabserrs(NBTRIALS); meanabserrs.setZero();
VectorXd lateral_input;
VectorXd total_exc(NBNEUR), delta_total_exc(NBNEUR), delta_total_exc_sq(NBNEUR), total_exc_prev(NBNEUR);
VectorXd delta_r(NBNEUR), delta_r_sq(NBNEUR), r_trace(NBNEUR), r_trace2(NBNEUR);
r_trace.fill(0); r_trace2.fill(0);
VectorXd delta_x(NBNEUR), delta_x_sq(NBNEUR), x_trace(NBNEUR), x_trace2(NBNEUR), delta_x_cu(NBNEUR);
//.........这里部分代码省略.........
示例11: set_seed
void set_seed(int s) {
rng.seed(s);
}
示例12:
RandomModule() {
random_engine.seed(std::random_device{}());
}
示例13: main
int main(int argc, char* argv[])
{
fstream myfile;
int PHASE=LEARNING;
if (argc > 1)
for (int nn=1; nn < argc; nn++)
{
if (strcmp(argv[nn], "test") == 0) { PHASE = TESTING; cout << "Test mode. " << endl; }
if (strcmp(argv[nn], "METHOD") == 0) { METHOD = argv[nn+1]; }
if (strcmp(argv[nn], "SUBW") == 0) { SUBW = atoi(argv[nn+1]); }
if (strcmp(argv[nn], "G") == 0) { G = atof(argv[nn+1]); }
if (strcmp(argv[nn], "ALPHABIAS") == 0) { ALPHABIAS = atof(argv[nn+1]); }
if (strcmp(argv[nn], "ETA") == 0) { ETA = atof(argv[nn+1]); }
if (strcmp(argv[nn], "STIMVAL") == 0) { STIMVAL = atof(argv[nn+1]); }
if (strcmp(argv[nn], "ALPHAMODUL") == 0) { ALPHAMODUL = atof(argv[nn+1]); }
if (strcmp(argv[nn], "NBNEUR") == 0) { NBNEUR = atoi(argv[nn+1]); }
if (strcmp(argv[nn], "PROBAMODUL") == 0) { PROBAMODUL = atof(argv[nn+1]); }
if (strcmp(argv[nn], "PROBAHEBB") == 0) { PROBAHEBB = atof(argv[nn+1]); }
if (strcmp(argv[nn], "ALPHATRACE") == 0) { ALPHATRACE = atof(argv[nn+1]); }
if (strcmp(argv[nn], "RNGSEED") == 0) { RNGSEED = atof(argv[nn+1]); }
if (strcmp(argv[nn], "MAXDW") == 0) { MAXDW = atof(argv[nn+1]); }
}
string SUFFIX = "_G" + to_string(G) + "_MAXDW" + to_string(MAXDW) + "_ETA" + to_string(ETA) + "_ALPHAMODUL" + to_string(ALPHAMODUL) + "_PROBAMODUL" + to_string(PROBAMODUL) + "_SUBW" +to_string(SUBW) + "_ALPHATRACE" + to_string(ALPHATRACE) + "_METHOD-" + METHOD + "_ALPHABIAS" + to_string(ALPHABIAS) + "_PROBAHEBB" + to_string(PROBAHEBB) + "_NBNEUR" + to_string(NBNEUR) + "_RNGSEED" + to_string(RNGSEED);
cout << SUFFIX << endl;
myrng.seed(RNGSEED);
double dt = 1.0;
double tau = 10.0;
int trialtype;
int NBTRIALS = 100017;
int TRIALTIME = 700 ; //500; // 1100
int STARTSTIM1 = 1, TIMESTIM1 = 500; // 200
//int STARTSTIM2 = 400, TIMESTIM2 = 0;
if (PHASE == TESTING)
NBTRIALS = 40*NBPATTERNS;
MatrixXd patterns[NBPATTERNS];
MatrixXd tgtresps[NBPATTERNS];
// Remember that input channel 0 is reserved for the unimplemented 'go' signal
MatrixXd dJ(NBOUT, NBNEUR); dJ.setZero();
MatrixXd win(NBNEUR, NBIN); randMat(win); //win.setRandom();// win.row(0).setZero(); // Uniformly between -1 and 1, except possibly for output cell (not even necessary).
cout << win.col(0).head(5) << endl;
MatrixXd J(NBNEUR, NBNEUR);
randJ(J);
if (PHASE == TESTING){
readWeights(J, "J.dat");
readWeights(win, "win.dat");
}
VectorXd meanerrs(NBTRIALS); meanerrs.setZero();
VectorXd lateral_input;
VectorXd dxthistrial(NBNEUR);
MatrixXd rs(NBNEUR, TRIALTIME); rs.setZero();
MatrixXd hebb(NBNEUR, NBNEUR);
VectorXd x(NBNEUR), r(NBNEUR), rprev(NBNEUR), dxdt(NBNEUR), k(NBNEUR),
input(NBIN), deltax(NBNEUR);
x.fill(0); r.fill(0);
VectorXd err(TRIALTIME);
VectorXd meanerrtrace(NBPATTERNS);
double meanerr;
MatrixXd dJtmp, Jprev, Jr;
double dtdivtau = dt / tau;
meanerrtrace.setZero();
for (int numtrial=0; numtrial < NBTRIALS; numtrial++)
{
if (PHASE == LEARNING)
//trialtype = (int)(numtrial/2) % NBPATTERNS;
trialtype = numtrial % NBPATTERNS;
else
trialtype = numtrial % NBPATTERNS;
hebb.setZero();
dJ.setZero();
//.........这里部分代码省略.........