続・Loto6のような1から48までの数を6個作るスクリプト

気が付かなかったのですが、コメント欄にもいくつかスクリプトが提示されていました。

"まつもとさん版もどき"
collection
collection := OrderedCollection new. 6 timesRepeat: [ | n | [collection includes: (n := 48 atRandom)] whileTrue. collection add: n]. ^collection
"咳さん版もどき"
collection
collection := OrderedCollection new. 1 to: 48 do: [: n | (48 - n + 1) atRandom < (6 - collection size + 1) ifTrue: [collection add: n]]. ^collection

Squeak でいう SequenceableCollection >> #shuffle 版は、Ruby だと、こんなふうに書けるんですね。

(1..48).sort_by{rand}[0..5]

sort_by{rand} …ですか。こりゃ、おじさん一本とられました(笑)。