Search code examples
randomcollectionssmalltalkpharo

How to get a specific number of random elements from a collection in Smalltalk?


How can I elegantly get a specific number (>1) of distinct, random elements from a collection?


Solution

  • This is something that I think looks more or less nice, but is not as efficient as it can be:

    yourCollection asSet asOrderedCollection shuffled first: numberOfElements