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

Side by Side Diff: sdk/lib/collection/list.dart

Issue 25931003: Make List.shuffle take an optional Random object to use. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment. Created 7 years, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/_internal/lib/js_array.dart ('k') | sdk/lib/core/core.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.collection; 5 part of dart.collection;
6 6
7 /** 7 /**
8 * Abstract implementation of a list. 8 * Abstract implementation of a list.
9 * 9 *
10 * All operations are defined in terms of `length`, `operator[]`, 10 * All operations are defined in terms of `length`, `operator[]`,
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 } 294 }
295 295
296 void sort([int compare(E a, E b)]) { 296 void sort([int compare(E a, E b)]) {
297 if (compare == null) { 297 if (compare == null) {
298 var defaultCompare = Comparable.compare; 298 var defaultCompare = Comparable.compare;
299 compare = defaultCompare; 299 compare = defaultCompare;
300 } 300 }
301 Sort.sort(this, compare); 301 Sort.sort(this, compare);
302 } 302 }
303 303
304 void shuffle() { 304 void shuffle([Random random]) {
305 Random random = new Random(); 305 if (random == null) random = new Random();
306 int length = this.length; 306 int length = this.length;
307 while (length > 1) { 307 while (length > 1) {
308 int pos = random.nextInt(length); 308 int pos = random.nextInt(length);
309 length -= 1; 309 length -= 1;
310 var tmp = this[length]; 310 var tmp = this[length];
311 this[length] = this[pos]; 311 this[length] = this[pos];
312 this[pos] = tmp; 312 this[pos] = tmp;
313 } 313 }
314 } 314 }
315 315
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 result.writeAll(this, ', '); 498 result.writeAll(this, ', ');
499 result.write(']'); 499 result.write(']');
500 } finally { 500 } finally {
501 assert(identical(_toStringList.last, this)); 501 assert(identical(_toStringList.last, this));
502 _toStringList.removeLast(); 502 _toStringList.removeLast();
503 } 503 }
504 504
505 return result.toString(); 505 return result.toString();
506 } 506 }
507 } 507 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/lib/js_array.dart ('k') | sdk/lib/core/core.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698