mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Make Rand deterministic (#1910)
Also re-enable auto-updating of Rand test (disabled in #1894)
This commit is contained in:
@@ -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
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user