|
Pokered Save Editor 2
Pokemon Red & Blue save file editor - Qt 6 C++/QML
|
Project-wide source of randomness, usable from both C++ and QML. More...
#include <random.h>
Public Member Functions | |
| float | range (const float end) const |
Random float in the half-open interval [0.00, end). | |
| int | rangeInclusive (const int start, const int end) const |
Random integer in the closed interval [start, end]. | |
| int | rangeExclusive (const int start, const int end) const |
Random integer in the half-open interval [start, end). | |
| bool | chanceFailure (const int percent) const |
Did a percent chance fail? | |
| bool | chanceFailure (const float percent) const |
Did a percent chance fail? | |
| bool | chanceSuccess (const int percent) const |
Did a percent chance succeed? | |
| bool | chanceSuccess (const float percent) const |
Did a percent chance succeed? | |
| bool | flipCoin () const |
| 50/50 coin flip via the integer path (chanceSuccess(50)). | |
| bool | flipCoinF () const |
| 50/50 coin flip via the float path (chanceSuccess(0.5f)). | |
| void | qmlProtect (const QQmlEngine *const engine) const |
| Pin this object to C++ ownership so QML's GC never deletes it. | |
Static Public Member Functions | |
| static Random * | inst () |
| < Convenience 50% coin flip (integer path), readable from QML. | |
Project-wide source of randomness, usable from both C++ and QML.
A thin, intention-revealing wrapper around Qt's global QRandomGenerator. It exists so the rest of the app (especially the map- and full-randomization features) can express randomness in domain terms - "give me a range", "flip a coin", "did this 30% chance succeed?" - instead of repeating bounds arithmetic everywhere.
| bool Random::chanceFailure | ( | const float | percent | ) | const |
Did a percent chance fail?
(float scale, 0.00-1.00).
| percent | Success likelihood as a fraction. |
true when the roll lands outside the success band. Definition at line 68 of file random.cpp.
References range().
| bool Random::chanceFailure | ( | const int | percent | ) | const |
Did a percent chance fail?
(integer scale, 0-100).
| percent | Success likelihood as a whole percentage. |
true when the roll lands outside the success band. Definition at line 62 of file random.cpp.
References rangeInclusive().
| bool Random::chanceSuccess | ( | const float | percent | ) | const |
Did a percent chance succeed?
(float scale, 0.00-1.00).
| percent | Success likelihood as a fraction. |
true when the roll lands inside the success band. Definition at line 79 of file random.cpp.
References range().
| bool Random::chanceSuccess | ( | const int | percent | ) | const |
Did a percent chance succeed?
(integer scale, 0-100).
| percent | Success likelihood as a whole percentage. |
true when the roll lands inside the success band. Definition at line 73 of file random.cpp.
References rangeInclusive().
Referenced by flipCoin(), flipCoinF(), PokemonBox::newPokemon(), PlayerPokedex::randomize(), PokemonBox::randomize(), WorldOther::randomize(), WorldTowns::randomize(), and ItemStorageBox::randomizeBag().
| bool Random::flipCoin | ( | ) | const |
50/50 coin flip via the integer path (chanceSuccess(50)).
Definition at line 84 of file random.cpp.
References chanceSuccess().
Referenced by PokemonBox::newPokemon(), PokemonBox::randomize(), and AreaPokemon::setTo().
| bool Random::flipCoinF | ( | ) | const |
50/50 coin flip via the float path (chanceSuccess(0.5f)).
Definition at line 89 of file random.cpp.
References chanceSuccess().
|
static |
< Convenience 50% coin flip (integer path), readable from QML.
Convenience 50% coin flip (float path), readable from QML. Returns the process-wide Random singleton, constructing it on first call.
Definition at line 31 of file random.cpp.
Referenced by PokemonBox::changeOtData(), PokemonBox::evolve(), ItemStorageBox::itemNew(), AreaTileset::loadFromData(), PokemonBox::newPokemon(), PokemonBox::newPokemon(), MapSearch::pickRandom(), Utility::qmlProtect(), SpriteFacing::random(), SpriteGrass::random(), SpriteMobility::random(), SpriteMovement::random(), Utility::random(), StarterPokemonDB::random3Starter(), StarterPokemonDB::randomAnyStarter(), AbstractRandomString::randomExample(), Area::randomize(), AreaAudio::randomize(), AreaGeneral::randomize(), AreaLoadedSprites::randomize(), AreaPlayer::randomize(), AreaPokemon::randomize(), AreaPokemonWild::randomize(), AreaTileset::randomize(), AreaWarps::randomize(), Daycare::randomize(), HallOfFame::randomize(), HoFPokemon::randomize(), HoFRecord::randomize(), Item::randomize(), PlayerBasics::randomize(), PlayerPokedex::randomize(), PlayerPokemon::randomize(), PokemonBox::randomize(), PokemonMove::randomize(), PokemonStorageBox::randomize(), Rival::randomize(), SignData::randomize(), SpriteData::randomize(), WarpData::randomize(), WorldOther::randomize(), WorldTowns::randomize(), ItemStorageBox::randomizeBag(), PlayerBasics::randomizeCoins(), PlayerBasics::randomizeID(), PlayerBasics::randomizeMoney(), WorldOther::randomizePlaytime(), PlayerBasics::randomizeStarter(), ItemStorageBox::randomizeStorage(), ItemStorageBox::randomUniqueInd(), PokemonBox::reRollDVs(), PokemonBox::reRollEVs(), PokemonBox::rollShiny(), Area::setTo(), AreaPokemon::setTo(), and AreaWarps::setTo().
| void Random::qmlProtect | ( | const QQmlEngine *const | engine | ) | const |
Pin this object to C++ ownership so QML's GC never deletes it.
| engine | The QML engine that would otherwise assume ownership. |
Definition at line 94 of file random.cpp.
References Utility::qmlProtectUtil().
Referenced by Utility::qmlProtect().
| float Random::range | ( | const float | end | ) | const |
Random float in the half-open interval [0.00, end).
| end | Exclusive upper bound. |
Definition at line 37 of file random.cpp.
Referenced by chanceFailure(), and chanceSuccess().
| int Random::rangeExclusive | ( | const int | start, |
| const int | end ) const |
Random integer in the half-open interval [start, end).
| start | Inclusive lower bound. |
| end | Exclusive upper bound. |
start unchanged. Definition at line 53 of file random.cpp.
Referenced by PokemonBox::evolve(), PokemonBox::newPokemon(), SpriteGrass::random(), StarterPokemonDB::random3Starter(), StarterPokemonDB::randomAnyStarter(), AbstractRandomString::randomExample(), AreaWarps::randomize(), HoFPokemon::randomize(), Rival::randomize(), SignData::randomize(), SpriteData::randomize(), WarpData::randomize(), PlayerBasics::randomizeCoins(), PlayerBasics::randomizeID(), PlayerBasics::randomizeMoney(), PlayerBasics::randomizeStarter(), and AreaWarps::setTo().
| int Random::rangeInclusive | ( | const int | start, |
| const int | end ) const |
Random integer in the closed interval [start, end].
| start | Inclusive lower bound. |
| end | Inclusive upper bound. |
start unchanged (degenerate ranges are treated as a fixed value rather than an error). Definition at line 42 of file random.cpp.
Referenced by chanceFailure(), chanceSuccess(), PokemonBox::changeOtData(), AreaTileset::loadFromData(), PokemonBox::newPokemon(), SpriteFacing::random(), SpriteMobility::random(), SpriteMovement::random(), AreaGeneral::randomize(), AreaPlayer::randomize(), AreaPokemon::randomize(), AreaPokemonWild::randomize(), AreaTileset::randomize(), HallOfFame::randomize(), HoFPokemon::randomize(), HoFRecord::randomize(), Item::randomize(), PlayerBasics::randomize(), PlayerPokemon::randomize(), PokemonBox::randomize(), PokemonMove::randomize(), PokemonStorageBox::randomize(), ItemStorageBox::randomizeBag(), WorldOther::randomizePlaytime(), ItemStorageBox::randomizeStorage(), PokemonBox::reRollEVs(), and PokemonBox::rollShiny().