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

Unified Diff: sdk/lib/collection/list.dart

Issue 24740003: Add List.shuffle(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 months 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
« no previous file with comments | « sdk/lib/collection/collection.dart ('k') | sdk/lib/core/list.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/collection/list.dart
diff --git a/sdk/lib/collection/list.dart b/sdk/lib/collection/list.dart
index 0e0c6116445554ade256019919d6f97b991f0044..4ff0f87d6f1cbee57dd27f985319dbee269d1e38 100644
--- a/sdk/lib/collection/list.dart
+++ b/sdk/lib/collection/list.dart
@@ -301,6 +301,17 @@ abstract class ListMixin<E> implements List<E> {
Sort.sort(this, compare);
}
+ void shuffle() {
+ Random random = new Random();
rakudrama 2013/09/26 13:33:25 This needs to be an optional parameter to assist i
floitsch 2013/09/26 14:25:22 I don't think that the additional parameter is wor
+ int length = this.length;
+ while (--length > 0) {
+ int pos = random.nextInt(length);
+ var tmp = this[length]
+ this[length] = this[pos];
+ list[pos] = tmp;
+ }
+ }
+
Map<int, E> asMap() {
return new ListMapView(this);
}
« no previous file with comments | « sdk/lib/collection/collection.dart ('k') | sdk/lib/core/list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698