Skip to content

Commit 1b90592

Browse files
authored
ofRandom & al: typos, format, wording (#7691)
1 parent 2de89ae commit 1b90592

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

apps/devApps/RandomExplorer/src/ofApp.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void ofApp::draw() {
7070
auto x = 220;
7171
ofDrawBitmapStringHighlight(size_string_, x, 40);
7272
ofDrawBitmapStringHighlight(dna_string_, x, 80);
73-
ofDrawBitmapStringHighlight("<- these values will be deterministic for a given seed (on all platforms)\n<- otherwise always different for non-deterministic", x+400, 80, ofColor(40,40,40));
73+
ofDrawBitmapStringHighlight("<- these values will be deterministic for a given seed (on all platforms)\n<- otherwise always different for non-deterministic", x + 400, 80, ofColor(40, 40, 40));
7474
ofDrawBitmapStringHighlight(shuffle_string_, x, 100);
7575
ofDrawBitmapStringHighlight("other random functions (like std::shuffle) can feed from the same thread-safe engine, ensuring coherence", x, 140);
7676

@@ -86,6 +86,6 @@ void ofApp::draw() {
8686
dists_["of"]->draw("OF/art-centric wrappers/utils", square_, gap_);
8787
dists_["old"]->draw("Previous implementation (reference)", square_, gap_);
8888

89-
ofDrawBitmapStringHighlight("Performance: e.g. on macOS M1,the old srand is faster\nthan uniform<float> in Debug, but slower in Release...\nPlease make sure to evaluate performance in Release!",
89+
ofDrawBitmapStringHighlight("Performance: on M1/M2 processors, the old srand is faster\nthan uniform<float> in Debug, but slower in Release...\nPlease make sure to evaluate performance in Release!",
9090
dists_["old"]->panel_.getPosition() + glm::vec2(0, square_ + gap_), ofColor(50, 0, 0), ofColor(ofColor::white));
9191
}

apps/devApps/RandomExplorer/src/ofApp.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ class ofApp : public ofBaseApp {
167167
auto colorize() {
168168

169169
size_t sum = 0;
170-
for (auto & group : { dists_["core"], dists_["special"], dists_["of"] })
170+
for (auto & group : { dists_["core"], dists_["special"], dists_["of"] }) {
171171
sum += group->dists_.size();
172+
}
172173
auto chunk = 255.0 / sum;
173174

174175
size_t i = 0; // to spread the hue; order below matters

libs/openFrameworks/utils/ofRandomEngine.h

+11-7
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,41 @@ class Engine : public of::utils::Singleton<Engine> {
2424
std::random_device rd_ {};
2525
std::seed_seq seq_ { rd_(), rd_(), rd_(), rd_() }; // 4 is considered fine for non-cryptographic needs
2626
std::mt19937 gen_ { seq_ };
27-
bool deterministic_ { false }; // by default the degine is non-deterministic (unpredictable)
27+
bool deterministic_ { false }; // by default the engine is non-deterministic (unpredictable)
2828

2929
public:
30-
/// return the generator for use in random distributions or functions
31-
///
30+
/// \brief return the generator for use in random distributions or functions
3231
/// \returns a reference to the mt19937 generator
3332
auto & gen() { return gen_; }
3433

35-
/// passes a value to seed the mt19937 generator
34+
/// \brief seeds the the mt19937 generator
35+
/// \param new_seed the seed value
3636
void seed(unsigned long new_seed) {
3737
deterministic_ = true;
3838
gen_.seed(new_seed);
3939
}
4040

41+
/// \brief return the generator for use in random distributions or functions
4142
/// \returns true or fall depending if the engine has been seeded with a deterministic value
4243
auto is_deterministic() const { return deterministic_; }
4344
};
4445

46+
/// \brief retrieve the engine instance
4547
/// \returns a reference to the engine instance
4648
inline auto engine() {
4749
return of::random::Engine::instance();
4850
}
4951

52+
/// \brief retrieve the generator instance
5053
/// \returns a reference to the generator within the engine instance
5154
inline auto & gen() {
5255
return of::random::Engine::instance()->gen();
5356
}
5457

55-
/// Passes a value to seed the mt19937 generator within the engine instance
56-
inline void seed(unsigned long seed) {
57-
of::random::Engine::instance()->seed(seed);
58+
/// \brief seeds the the mt19937 generator
59+
/// \param new_seed the seed value
60+
inline void seed(unsigned long new_seed) {
61+
of::random::Engine::instance()->seed(new_seed);
5862
}
5963

6064
} // end namespace of::random

libs/openFrameworks/utils/ofSingleton.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ namespace of::utils {
1414
template <typename Derived>
1515
class Singleton {
1616
public:
17+
/// \brief constructs the instance
1718
template <typename... Args>
1819
static void construct(Args &&... args) {
1920
struct Dummy : public Derived {
2021
using Derived::Derived;
2122
void prohibit_construct_from_derived() const override { }
2223
};
23-
24+
2425
using Instance = Dummy;
2526
if (!instance_.load(std::memory_order_acquire)) {
2627
std::lock_guard lock { mutex_ };
@@ -30,6 +31,7 @@ class Singleton {
3031
}
3132
}
3233

34+
/// \brief destroys the instance
3335
static void destruct() {
3436
if (instance_.load(std::memory_order_acquire)) {
3537
std::lock_guard lock { mutex_ };
@@ -40,6 +42,7 @@ class Singleton {
4042
}
4143
}
4244

45+
/// \brief returns the instance
4346
static Derived * instance() {
4447
auto * the_instance = instance_.load(std::memory_order_acquire);
4548
if (!the_instance) {

0 commit comments

Comments
 (0)