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

Unified Diff: runtime/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: runtime/lib/math_patch.dart
diff --git a/runtime/lib/math_patch.dart b/runtime/lib/math_patch.dart
index 0612d3db2ff7731f55241be980faac219b1b3497..e407633e4f360815e4a55920d984bcacf5b92704 100644
--- a/runtime/lib/math_patch.dart
+++ b/runtime/lib/math_patch.dart
@@ -68,6 +68,15 @@ class _Random implements Random {
return result;
}
+int nextIntRange(int min, int max) {
+ int range = max - min;
+ if (range <= 0) {
floitsch 2013/11/18 13:36:03 Doesn't test if max or min is negative.
+ throw new ArgumentError("min is greater then or equal to max");
floitsch 2013/11/18 13:36:03 Would be nice to have the values in the error mess
+ }
+ range = nextInt(range);
floitsch 2013/11/18 13:36:03 I wouldn't have called the result of the random-ca
+ return min + range;
+ }
+
double nextDouble() {
return ((nextInt(1 << 26) << 27) + nextInt(1 << 27)) / _POW2_53_D;
}

Powered by Google App Engine
This is Rietveld 408576698