Skip to content

Commit 5dd050a

Browse files
committed
Fix RAND function to actually use TE_RAND_SEED and use persistent RNG
Fix stale comment
1 parent 6b52aa3 commit 5dd050a

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

tinyexpr.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,16 +499,15 @@ namespace te_builtins
499499
static te_type te_random()
500500
{
501501
#ifdef TE_RAND_SEED
502-
std::mt19937 gen(static_cast<unsigned int>(RAND_SEED));
502+
static std::mt19937 gen(static_cast<unsigned int>(TE_RAND_SEED));
503503
#elif defined(TE_RAND_SEED_TIME)
504-
std::mt19937 gen(static_cast<unsigned int>(time(nullptr)));
504+
static std::mt19937 gen(static_cast<unsigned int>(std::time(nullptr)));
505505
#else
506-
static std::random_device rdev;
507-
std::mt19937 gen(rdev());
506+
static std::mt19937 gen(std::random_device{}());
508507
#endif
509508

510-
std::uniform_real_distribution<te_type> distr(0, 1);
511-
return distr(gen);
509+
static std::uniform_real_distribution<te_type> distribute(0, 1);
510+
return distribute(gen);
512511
}
513512

514513
[[nodiscard]]

tinyexpr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
constexpr int TINYEXPR_CPP_MAJOR_VERSION = 1;
8282
constexpr int TINYEXPR_CPP_MINOR_VERSION = 0;
8383
constexpr int TINYEXPR_CPP_PATCH_VERSION = 1;
84-
constexpr int TINYEXPR_CPP_TWEAK_VERSION = 0;
84+
constexpr int TINYEXPR_CPP_TWEAK_VERSION = 1;
8585
#define TINYEXPR_CPP_COPYRIGHT \
8686
"TinyExpr: Copyright (c) 2015-2020 Lewis Van Winkle\n" \
8787
"TinyExpr++: Copyright (c) 2020-2025 Blake Madden"
@@ -252,7 +252,7 @@ enum te_variable_flags
252252
/// @brief Don't update when simple evaluation is run
253253
/// (i.e., only updated when expression is compiled).
254254
TE_PURE = (1 << 0),
255-
/// @brief Function that can take 1-7 argument (unused arguments are set to NaN).
255+
/// @brief Function that can take 1-24 argument (unused arguments are set to NaN).
256256
TE_VARIADIC = (1 << 1)
257257
};
258258

0 commit comments

Comments
 (0)