13 #include "nutools/RandomUtils/NuRandomService.h" 21 #include "CLHEP/Random/RandomEngine.h" 22 #include "CLHEP/Random/RandFlat.h" 29 namespace NuRandomService {
36 if (!art_exc)
return false;
44 if ( (art_exc->explain_self().find(
"NuRandomService") == std::string::npos)
45 && (art_exc->explain_self().find(
"SeedMaster") == std::string::npos)
65 unsigned short RollStat(CLHEP::RandFlat& rand) {
68 for (
int i = 0; i < 4; ++i) {
69 unsigned int roll = 1 + rand.fireInt(0, 6);
71 if (min > roll) min = roll;
80 CLHEP::RandFlat flat(engine);
81 constexpr
size_t NStats = 6;
82 static const std::array<std::string, NStats> statNames
83 = {{
"STR",
"DEX",
"CON",
"INT",
"WIS",
"CHA" }};
84 std::array<unsigned short int, NStats> stats;
85 std::generate(stats.begin(), stats.end(), [&flat]{
return RollStat(flat); });
88 std::ostringstream sstr;
89 for (
size_t iStat = 0; iStat < NStats; ++iStat) {
90 sstr <<
" " << statNames[iStat] <<
"=" <<
std::setw(2) << stats[iStat];
91 bonus += stats[iStat] / 2 - 5;
93 sstr <<
" [bonus: " <<
std::setw(3) << std::showpos << bonus <<
"]";
100 {
return engine.getSeed(); }
art::detail::EngineCreator::seed_t seed_t
Type of seed.
std::string CreateCharacter(CLHEP::HepRandomEngine &engine)
Creates a "character statistics" using the specified random engine.
Functions used in NuRandomService tests.
CodeOutputInterface * code
Q_EXPORT QTSManip setw(int w)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
seed_t readSeed(CLHEP::HepRandomEngine const &engine)
Returns the seed of the specified engine (CLHEP overload)
bool isSeedServiceException(std::exception const &e)
Returns whether the exception looks to be from NuRandomService.
cet::coded_exception< error, detail::translate > exception
unsigned short RollStat(CLHEP::RandFlat &rand)
Extracts "statistics" from a flat random number distribution.