diff --git a/explorer/interpreter/interpreter.cpp b/explorer/interpreter/interpreter.cpp index 088954a7e317..4026b141885f 100644 --- a/explorer/interpreter/interpreter.cpp +++ b/explorer/interpreter/interpreter.cpp @@ -1213,8 +1213,10 @@ auto Interpreter::StepExp() -> ErrorOr { CARBON_CHECK(args.size() == 2); const auto& low = cast(*args[0]).value(); const auto& high = cast(*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(r)); } case IntrinsicExpression::Intrinsic::IntEq: { diff --git a/explorer/testdata/random/random.carbon b/explorer/testdata/random/random.carbon index 6080b1c90718..ee99e7c88651 100644 --- a/explorer/testdata/random/random.carbon +++ b/explorer/testdata/random/random.carbon @@ -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;