[squeak-dev] The Trunk: Collections-ul.351.mcz

commits at source.squeak.org commits at source.squeak.org
Sun Mar 28 00:14:01 UTC 2010


Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.351.mcz

==================== Summary ====================

Name: Collections-ul.351
Author: ul
Time: 28 March 2010, 1:08:22.188 am
UUID: 4bfd8358-2138-6e4c-b4a7-060897bffd7e
Ancestors: Collections-ul.350

- added #shuffle and #shuffleBy: to shuffle SequenceableCollections in-place

=============== Diff against Collections-ul.350 ===============

Item was changed:
+ ----- Method: SequenceableCollection>>shuffledBy: (in category 'shuffling') -----
- ----- Method: SequenceableCollection>>shuffledBy: (in category 'copying') -----
  shuffledBy: aRandom
  	"Durstenfeld's version of the Fisher-Yates shuffle"
  
+ 	^self copy shuffleBy: aRandom!
- 	| copy | 
- 	copy := self copy.
- 	copy size to: 2 by: -1 do: [ :i | 
- 		copy swap: i with: (aRandom nextInt: i) ].
- 	^copy!

Item was added:
+ ----- Method: SequenceableCollection>>shuffle (in category 'shuffling') -----
+ shuffle
+ 
+ 	^self shuffleBy: Collection randomForPicking!

Item was added:
+ ----- Method: SequenceableCollection>>shuffleBy: (in category 'shuffling') -----
+ shuffleBy: aRandom
+ 	"Durstenfeld's version of the Fisher-Yates shuffle"
+ 
+ 	self size to: 2 by: -1 do: [ :i | 
+ 		self swap: i with: (aRandom nextInt: i) ]!




More information about the Squeak-dev mailing list