/* return 0 for all done, else 1+SPR number. Zero makes a nicer sentinel than * UINT_MAX for users of the library, but beware of the offset when debugging. * * root moving: loop through normal SPRs, then return negative sprnums. */ int spr_next_spr( struct spr_tree *tree ) { int tmp = FALSE; unsigned sprnum; // tree->rootmove=1; //ROOTMOVE ONLY if(tree->rootmove == 0){ do{ // try SPRs until we find a legal one, or loop to beginning sprnum = lcg( &tree->lcg ); if(UINT_MAX == sprnum) break; tmp = spr_sprnum(tree, sprnum+1); if (tmp && tree->dups) tmp = spr_add_dup(tree, tree->root); }while(!tmp); if(UINT_MAX != sprnum) return 1 + sprnum; } #ifdef NO_ROOT_MOVING return FALSE; #else do{ if(tree->rootmove++ > (tree->nodes*tree->nodes*tree->nodes)) return FALSE; tmp = spr_sprnum(tree, -(int)(tree->rootmove+1)); if (tmp && tree->dups) tmp = spr_add_dup(tree, tree->root); }while(!tmp); return tree->lastspr = -(int)(tree->rootmove+1); #endif }
void KCalendarSystemQDatePrivate::loadDefaultEraList() { QString name, shortName, format; KConfigGroup lcg(config(), QString::fromLatin1("Locale")); KConfigGroup cg = lcg.group(QString::fromLatin1("KCalendarSystem %1").arg(q->calendarType(q->calendarSystem()))); m_useCommonEra = cg.readEntry("UseCommonEra", false); if (m_useCommonEra) { name = i18nc("Calendar Era: Gregorian Common Era, years < 0, LongFormat", "Before Common Era"); shortName = i18nc("Calendar Era: Gregorian Common Era, years < 0, ShortFormat", "BCE"); } else { name = i18nc("Calendar Era: Gregorian Christian Era, years < 0, LongFormat", "Before Christ"); shortName = i18nc("Calendar Era: Gregorian Christian Era, years < 0, ShortFormat", "BC"); } format = i18nc("(kdedt-format) Gregorian, BC, full era year format used for %EY, e.g. 2000 BC", "%Ey %EC"); addEra('-', 1, q->epoch().addDays(-1), -1, q->earliestValidDate(), name, shortName, format); if (m_useCommonEra) { name = i18nc("Calendar Era: Gregorian Common Era, years > 0, LongFormat", "Common Era"); shortName = i18nc("Calendar Era: Gregorian Common Era, years > 0, ShortFormat", "CE"); } else { name = i18nc("Calendar Era: Gregorian Christian Era, years > 0, LongFormat", "Anno Domini"); shortName = i18nc("Calendar Era: Gregorian Christian Era, years > 0, ShortFormat", "AD"); } format = i18nc("(kdedt-format) Gregorian, AD, full era year format used for %EY, e.g. 2000 AD", "%Ey %EC"); addEra('+', 1, q->epoch(), 1, q->latestValidDate(), name, shortName, format); }
int main(){ LCG lcg(999); for(int i = 0; i < 14; i++){ std::cout << lcg.rand(100) <<std::endl; } return 0; }
void invokeTestSuite(int option, char *streamFile) { fprintf(freqfp, "________________________________________________________________________________\n\n"); fprintf(freqfp, "\t\tFILE = %s\t\tALPHA = %6.4f\n", streamFile, ALPHA); fprintf(freqfp, "________________________________________________________________________________\n\n"); printf("________________________________________________________________________________\n\n"); printf("FILE = %s BITS = %i BITSTREAMS = %i ALPHA = %6.4f\n", streamFile, tp.n, tp.numOfBitStreams, ALPHA); printf("________________________________________________________________________________\n\n"); if ( option != 0 ) printf("Statistical Testing In Progress.........\n\n"); switch( option ) { case 0: fileBasedBitStreams(streamFile); break; case 1: lcg(); break; case 2: quadRes1(); break; case 3: quadRes2(); break; case 4: cubicRes(); break; case 5: exclusiveOR(); break; case 6: modExp(); break; case 7: bbs(); break; case 8: micali_schnorr(); break; case 9: SHA1(); break; /* INTRODUCE NEW PSEUDO RANDOM NUMBER GENERATORS HERE */ default: printf("Error in invokeTestSuite!\n"); break; } printf("Statistical Testing Complete!!!!!!!!!!!!\n\n"); }
// initialize the rng with a seed // for the same seed, will generate the same sequence of pseudo random numbers std::mt19937 initialize_twister( std::size_t seed ) { static constexpr std::size_t NDISCARD = 1024 ; std::minstd_rand lcg(seed) ; lcg.discard(NDISCARD) ; std::size_t seeds[ std::mt19937::state_size ] ; std::generate_n( seeds, std::mt19937::state_size, lcg ) ; std::seed_seq seed_sequence( std::begin(seeds), std::end(seeds) ) ; std::mt19937 twister { seed_sequence } ; // warm-up twister.discard(NDISCARD) ; // more warm-up return twister ; }
int judge_seed(uint32_t seed) { LCG lcg(seed); int shuu = 3; bool is_open_level = false; bool is_hgss = false; int num_bonus = 2; vector<int> trainers = rand_trainers(lcg, shuu, is_hgss); vector<Entry> entries = rand_starter_entries(lcg, is_open_level, shuu, num_bonus); vector<Poke> starters = starter_entiries_to_poke(is_open_level, shuu, 0, entries, rand_pid(lcg, entries)); lcg.step(2); // shuffle LCG l(lcg.seed); vector<Poke> playerPokes = { starters[0], starters[4], starters[5] }; vector<Poke> prev; int i; for (i = 1; i <= 1; i++) { vector<Entry> seen = apply(i == 1 ? starters : playerPokes + prev, [](Poke p) { return p->entry; }); RankObject rank = trainer_id_to_rank(is_open_level, is_hgss, trainers[i - 1]); vector<Poke> pokes = rand_enemy_poke(l, rank, seen); //bool win = completely_winnable(playerPokes, pokes, true); bool win = false; cout << tohex(seed) << ": " << win << endl; if (!win) { break; } prev = pokes; rand_gap(l, shuu, i, rank); } if (i - 1 >= 1) { return 2; //cout << tohex(seed) << endl; } return 1; }
void Ship::output(){ ofstream file; file.open("Report.txt"); file << "[table]" << endl; cout << fixed << setprecision(2) << "Length: \t\t\t\t" << v.Lpp << " m" << endl; file << fixed << setprecision(2) << "[tr][td]Length: \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t[/td][td]" << v.Lpp << " m[/td][/tr]" << endl; cout << "Beam: \t\t\t\t\t" << v.B << " m" << endl; file << "[tr][td]Beam: [/td][td]" << v.B << " m[/td][/tr]" << endl; cout << "Draft: \t\t\t\t\t" << v.D << " m" << endl; file << "[tr][td]Draft: [/td][td]" << v.D << " m[/td][/tr]" << endl; cout << "Freeboard: \t\t\t\t" << v.fB << " m" << endl; file << "[tr][td]Freeboard: [/td][td]" << v.fB << " m[/td][/tr]" << endl; cout << setprecision(3) << "Block Coefficient: \t\t\t" << Cb() << endl; file << setprecision(3) << "[tr][td]Block Coefficient: [/td][td]" << Cb() << "[/td][/tr]" << endl; cout << setprecision(0) << "Displacement: \t\t\t\t" << Vol() << " t" << endl; file << setprecision(0) << "[tr][td]Displacement: [/td][td]" << Vol() << " t[/td][/tr]" << endl; cout << "Lightship: \t\t\t\t" << Wh() + Wwo() + Wm() + We() + Wspus() + Bunker() << " t" << endl; file << "[tr][td]Lightship: [/td][td]" << Lightship() << " t[/td][/tr]" << endl; cout << setprecision(1) << "\nMax Speed: \t\t\t\t" << v.Vk << " kn" << endl; file << setprecision(1) << "\n[tr][td]Max Speed: [/td][td]" << v.Vk << " kn[/td][/tr]" << endl; cout << "Cruise Speed: \t\t\t\t" << v.Vc << " kn / " << v.Range << " nm" << endl; file << "[tr][td]Cruise Speed: [/td][td]" << v.Vc << " kn / " << v.Range << " nm[/td][/tr]" << endl; cout << "Engine: \t\t\t\t"; file << "[tr][td]Engine: [/td][td]"; switch(e.Gear){ case Direct: cout << "Direct "; file << "Direct "; break; case Geared: cout << "Geared "; file << "Geared "; break; case Turbo_Electric: cout << "Turbo-Electric "; file << "Turbo-Electric "; break; default: cout << "Unknown"; file << "Unknown"; } switch(e.Eng){ case Diesel2stk: cout << "Two Stroke Diesel" << endl; file << "Two Stroke Diesel"; break; case Diesel4stk: cout << "Four Stroke Diesel" << endl; file << "Four Stroke Diesel" << endl; break; case QuadExp: cout << "Quadruple Expansion Reciprocating Engine" << endl; file << "Quadruple Expansion Reciprocating Engine"; break; case TripExp: cout << "Triple Expansion Reciprocating Engine" << endl; file << "Triple Expansion Reciprocating Engine"; break; case SimExp: cout << "Simple Reciprocating Engine" << endl; file << "Simple Reciprocating Engine"; break; case SteamTur: cout << "Steam Turbine" << endl; file << "Steam Turbine"; break; default: cout << endl; } file << "[/td][/tr]" << endl; cout << setprecision(0) << "Power Delivered: \t\t\t" << Pd(v.Vk) << " hp" << endl; file << setprecision(0) << "[tr][td]Power Delivered: [/td][td]" << Pd(v.Vk) << " hp[/td][/tr]" << endl; cout << setprecision(2) << "Total Efficiency: \t\t\t" << NUt()*100 << "%" << endl; file << setprecision(2) << "[tr][td]Total Efficiency: [/td][td]" << NUt()*100 << "%[/td][/tr]" << endl; cout << setprecision(3) << "Froude Number: \t\t\t\t" << Fn() << endl; file << setprecision(3) << "[tr][td]Froude Number: [/td][td]" << Fn() << "[/td][/tr]" << endl; cout << setprecision(0) << "Bunker Size: \t\t\t\t" << Bunker() << " t" << endl; file << setprecision(0) << "[tr][td]Bunker Size: [/td][td]" << Bunker() << " t[/td][/tr]" << endl; cout << "Service Allowance: \t\t\t" << e.SA << "%" << endl; file << "[tr][td]Service Allowance: [/td][td]" << e.SA << "%[/td][/tr]" << endl; cout << setprecision(2); file << setprecision(2); cout << "Length of Superstructure: \t\t" << v.Lspus << " m" << endl; file << "[tr][td]Length of Superstructure: [/td][td]" << v.Lspus << " m[/td][/tr]" << endl; cout << "Aftbody Shape: \t\t\t\t"; file << "[tr][td]Aftbody Shape: [/td][td]"; switch(e.Faa){ case V: cout << "V" << endl; file << "V"; break; case U: cout << "U" << endl; file << "U"; break; case N: cout << "N" << endl; file << "N"; break; default: cout << "N" << endl; file << "N"; } file << "[/td][/tr]"; cout << "\nLongitudinal Center of Buoyancy: \t" << lcb() << "%" << endl; file << "\n[tr][td]Longitudinal Center of Buoyancy: [/td][td]" << lcb() << "% / " << lcb()*v.Lpp << " m from midpoint[/td][/tr]" << endl; cout << "Longitudinal Center of Gravity: \t" << lcg() << "%" << endl; file << "[tr][td]Longitudinal Center of Gravity: [/td][td]" << lcg() << "% / " << lcg()*v.Lpp << " m from midpoint[/td][/tr]" << endl; cout << "Vertical Center of Gravity: \t\t" << KGh() << " m" << endl; file << "[tr][td]Vertical Center of Gravity: [/td][td]" << KGh() << " m[/td][/tr]" << endl; cout << "Metacentric Height: \t\t\t" << GM() << " m" << endl; file << "[tr][td]Metacentric Height: [/td][td]" << GM() << " m[/td][/tr]" << endl; cout << "Roll Period: \t\t\t\t" << TR() << " s" << endl; file << "[tr][td]Roll Period: [/td][td]" << TR() << " s[/td][/tr]" << endl; cout << "\nBow Entrance Angle: \t\t\t" << iE() << " deg" << endl; file << "\n[tr][td]Bow Entrance Angle: [/td][td]" << iE() << " deg[/td][/tr]" << endl; cout << "Length of Engine Room: \t\t\t" << Lcm() << " m" << endl; file << "[tr][td]Length of Engine Room: [/td][td]" << Lcm() << " m[/td][/tr]" << endl; cout << setprecision(0) << "\nMain Belt: \t\t\t\t" << arm.mb_Ttop << " / " << arm.mb_Tbot << " mm at " << arm.b_deg << " degrees, " << arm.b_L << " m long with " << arm.b_H << " m above and " << arm.b_Db << " m below water" << endl; file << setprecision(0) << "\n[tr][td]Main Belt: [/td][td]" << arm.mb_Ttop << " / " << arm.mb_Tbot << " mm, " << arm.b_L << " m long with " << arm.b_H << " m above and " << arm.b_Db << " m below water[/td][/tr]" << endl; cout << "End Belt: \t\t\t\t" << arm.eb_Ttop << " / " << arm.eb_Tbot << " mm" << endl; file << "[tr][td]End Belt: [/td][td]" << arm.eb_Ttop << " / " << arm.eb_Tbot << " mm[/td][/tr]" << endl; cout << "Upper Belt: \t\t\t\t" << arm.ub_Ttop << " / " << arm.ub_Tbot << " mm, " << arm.b_uL << " m long" << endl; file << "[tr][td]Upper Belt: [/td][td]" << arm.ub_Ttop << " / " << arm.ub_Tbot << " mm, " << arm.b_uL << " m long[/td][/tr]" << endl; cout << "Main Deck: \t\t\t\t" << arm.md_T << " mm covering " << arm.md_P << "% / " << arm.md_P * v.Lpp << " m of deck" << endl; file << "[tr][td]Main Deck: [/td][td]" << arm.md_T << " m covering " << arm.md_P << "% / " << arm.md_P * v.Lpp << " m of deck[/td][/tr]" << endl; cout << "Weather Deck: \t\t\t\t" << arm.wd_T << " mm covering " << arm.wd_P << "% / " << arm.wd_P * v.Lpp << " m of deck" << endl; file << "[tr][td]Weather Deck: [/td][td]" << arm.wd_T << " m covering " << arm.wd_P << "% / " << arm.wd_P * v.Lpp << " m of deck[/td][/tr]" << endl; cout << "Splinter Deck: \t\t\t\t" << arm.sd_T << " mm covering " << arm.sd_P << "% / " << arm.sd_P * v.Lpp << " m of deck" << endl; file << "[tr][td]Splinter Deck: [/td][td]" << arm.sd_T << " m covering " << arm.sd_P << "% / " << arm.sd_P * v.Lpp << " m of deck[/td][/tr]" << endl; cout << "Ends Deck: \t\t\t\t" << arm.ed_T << " mm" << endl; file << "[tr][td]Ends Deck: [/td][td]" << arm.ed_T << " mm[/td][/tr]" << endl; cout << "Bulkhead: \t\t\t\t" << arm.blk_T << " mm in " << arm.blk_Lct << "x" << arm.blk_D << " m layers, " << arm.blk_L << " m long, " << arm.blk_H << " m tall" << endl; file << "[tr][td]Bulkhead: [/td][td]" << arm.blk_T << " mm in " << arm.blk_Lct << "x" << arm.blk_D << " m layers, " << arm.blk_L << " m long, " << arm.blk_H << " m tall[/td][/tr]" << endl; file << "[/table]" << endl; file.close(); }