Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Unified Diff: sdk/lib/_internal/compiler/implementation/lib/math_patch.dart

Issue 11367087: Added nextIntRange to dartvm and dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/lib/math_patch.dart
diff --git a/sdk/lib/_internal/compiler/implementation/lib/math_patch.dart b/sdk/lib/_internal/compiler/implementation/lib/math_patch.dart
index b20276efa101c5aad9e728ab4130eaee1d78cc30..1c74daef012313176b7c73b364b541af978028db 100644
--- a/sdk/lib/_internal/compiler/implementation/lib/math_patch.dart
+++ b/sdk/lib/_internal/compiler/implementation/lib/math_patch.dart
@@ -54,6 +54,15 @@ class _Random implements Random {
return JS("int", "(Math.random() * #) >>> 0", max);
}
+ int nextIntRange(int min, int max) {
+ if (max < 0) throw new ArgumentError("negative max: $max");
+ if (min >= max) throw new ArgumentError("min is greater then or equal to max");
floitsch 2013/11/18 13:36:03 80 chars. And the error message should contain the
+
+ int range = max - min;
+ range = nextInt(range);
floitsch 2013/11/18 13:36:03 Don't reuse the variable (which is not a range). I
+ return min + range;
+ }
+
/**
* Generates a positive random floating point value uniformly distributed on
* the range from 0.0, inclusive, to 1.0, exclusive.

Powered by Google App Engine
This is Rietveld 408576698