add scheduler random function (rnd(x) => random 0..x)

This commit is contained in:
MichaelDvP
2025-03-22 11:41:00 +01:00
parent b097e372e4
commit 1da08633ec

View File

@@ -102,6 +102,9 @@ std::deque<Token> exprToTokens(const std::string & expr) {
} else if (strncmp(p, "hex", 3) == 0) { } else if (strncmp(p, "hex", 3) == 0) {
p += 2; p += 2;
tokens.emplace_back(Token::Type::Unary, "h", 5); tokens.emplace_back(Token::Type::Unary, "h", 5);
} else if (strncmp(p, "rnd", 3) == 0) {
p += 2;
tokens.emplace_back(Token::Type::Unary, "d", 5);
} else if ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p == '_') || (*p & 0x80)) { } else if ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p == '_') || (*p & 0x80)) {
const auto * b = p; const auto * b = p;
while ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p == '_') || (*p & 0x80)) { while ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p == '_') || (*p & 0x80)) {
@@ -526,6 +529,9 @@ std::string calculate(const std::string & expr) {
case 'x': case 'x':
stack.push_back(to_hex(static_cast<int>(rhd))); stack.push_back(to_hex(static_cast<int>(rhd)));
break; break;
case 'd':
stack.push_back(to_string(rhd * esp_random() / UINT32_MAX));
break;
} }
} break; } break;
case Token::Type::Compare: { case Token::Type::Compare: {