そんな おおしまさんのリクエストにお応えして…

n(LotoN の N)と m(選ぶべき数字の最大)を振ってベンチマークをとってみました。

n = 6, m = ...
       manually  #addIfNotPresent:  a Set     shuffled
96 =>     141.1        148.3        165.5       1769.1 
48 =>     147.0        150.5        172.3        892.2 
24 =>     154.9        159.2        177.6        454.8 
12 =>     178.1        182.4        194.5        239.5 
 6 =>     295.6        303.7        289.9        134.4 
        
m = 48, n = ...
       manually  #addIfNotPresent:  a Set     shuffled
 2 =>      48.3         49.3         45.6        894.7 
 4 =>      92.3         94.5         84.3        893.4 
 6 =>     145.9        148.5        169.8        890.8 
 8 =>     206.7        211.8        214.7        891.7 
10 =>     272.3        278.0        310.9        892.1 
12 =>     353.1        361.7        361.8        893.3

おおかたの予想通りですね。shuffled は意外と使えません(^_^;)。逆に a Set は(このケースでは)思っていたより健闘しています。n が十分小さいのが効いているのでしょうね。

コードはこちら。

'From SqueakNihongo6.1 of 17 April 2004 [latest update: #0]'!
Object subclass: #LotoN
  instanceVariableNames: ''
  classVariableNames: ''
  poolDictionaries: ''
  category: 'Category-Loat6'!

LotoN class
  instanceVariableNames: ''!

!LotoN class methodsFor: 'generating' stamp: 'sumim 8/24/2004'!
choose: n formShuffled: m
  "shuffled before picking-up"
  ^(1 to: m) asArray shuffled first: n! !

!LotoN class methodsFor: 'generating' stamp: 'sumim 8/24/2004'!
choose: n thenAddingByPresenceFrom: m
  "using #addIfNotPresent: method"
  | collection |
  collection _ OrderedCollection new.
  [collection size < n] whileTrue: [collection addIfNotPresent: m atRandom].
  ^collection! !

!LotoN class methodsFor: 'generating' stamp: 'sumim 8/24/2004'!
choose: n thenAddingProcedurallyFrom: m
  "checking procedurally"
  | collection |
  collection _ OrderedCollection new.
  [collection size < n] whileTrue: [
    | rand |
    rand _ m atRandom.
    (collection includes: rand) not ifTrue: [collection add: rand]].
  ^ collection! !

!LotoN class methodsFor: 'generating' stamp: 'sumim 8/24/2004'!
choose: n thenAddingToASetFrom: m
  "delegating to a Set"
  | collection |
  collection _ Set new.
  [collection size < n] whileTrue: [collection add: m atRandom].
  ^collection! !

!LotoN class methodsFor: 'benchmark' stamp: 'sumim 8/24/2004'!
benchmarksVaryingM: mSeries
  | generators |
  generators _ self class allMethodsInCategory: 'generating'.
  generators do: [: generator |
    Transcript cr; cr.
    Transcript show: (self class firstCommentAt: generator), '; where n = 6, m = ...'.
    mSeries do: [: m |
      Transcript cr; show: m printString, ' => ', ((1 to: 10) collect: [: void |
        Smalltalk garbageCollect.
        [1e3 timesRepeat: [
          LotoN perform: generator with: 6 with: m]
        ] timeToRun]) average asFloat printString]]! !

!LotoN class methodsFor: 'benchmark' stamp: 'sumim 8/24/2004'!
benchmarksVaryingN: nSeries
  | generators |
  generators _ self class allMethodsInCategory: 'generating'.
  generators do: [: generator |
    Transcript cr; cr.
    Transcript show: (self class firstCommentAt: generator), '; where m = 48, n = ...'.
    nSeries do: [: n |
      Transcript cr; show: n printString, ' => ', ((1 to: 10) collect: [: void |
        Smalltalk garbageCollect.
        [1e3 timesRepeat: [
          LotoN perform: generator with: n with: 48]
        ] timeToRun]) average asFloat printString]]! !

(PopUpMenu confirm: 'execute benchmark immediately?') ifTrue: [
  ActiveWorld findATranscript: ActiveHand.
  LotoN benchmarksVaryingM: #(96 48 24 12 6).
  LotoN benchmarksVaryingN: #(2 4 6 8 10 12)]