Chromium Code Reviews| 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); |
| } |