Make Rand deterministic (#1910)

Also re-enable auto-updating of Rand test (disabled in #1894)
This commit is contained in:
Geoff Romer
2022-08-09 14:17:26 -07:00
committed by GitHub
parent f9bd01536b
commit 4ed8180bc7
2 changed files with 6 additions and 3 deletions
+4 -2
View File
@@ -1213,8 +1213,10 @@ auto Interpreter::StepExp() -> ErrorOr<Success> {
CARBON_CHECK(args.size() == 2);
const auto& low = cast<IntValue>(*args[0]).value();
const auto& high = cast<IntValue>(*args[1]).value();
std::uniform_int_distribution<> distr(low, high);
int r = distr(generator);
CARBON_CHECK(high > low);
// We avoid using std::uniform_int_distribution because it's not
// reproducible across builds/platforms.
int r = (generator() % (high - low)) + low;
return todo_.FinishAction(arena_->New<IntValue>(r));
}
case IntrinsicExpression::Intrinsic::IntEq: {
+2 -1
View File
@@ -6,7 +6,8 @@
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes=false %s
// RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
// RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
// NOAUTOUPDATE
// AUTOUPDATE: %{explorer} %s
// CHECK: Nice!
// CHECK: result: 0
package ExplorerTest api;