<div dir="ltr">Consider this,<div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)"><span style="color:rgb(187,44,162)">struct</span><span style="color:rgb(0,0,0)"> RandomGenerator : </span>GeneratorType<span style="color:rgb(0,0,0)">, </span>SequenceType<span style="color:rgb(0,0,0)"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px">    </p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:rgb(187,44,162)">mutating</span> <span style="color:rgb(187,44,162)">func</span> next() -&gt; <span style="color:rgb(112,61,170)">UInt32</span>? {</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">        <span style="color:rgb(187,44,162)">return</span> <span style="color:rgb(61,29,129)">arc4random</span>()</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    }</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</p><div dir="auto" style="word-wrap:break-word"><br></div><div style="word-wrap:break-word">what&#39;s the expected result of follows??</div><div dir="auto" style="word-wrap:break-word"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="color:rgb(187,44,162)">let</span><span style="color:rgb(0,0,0)"> random = </span>RandomGenerator<span style="color:rgb(0,0,0)">()</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">let</span> resultA = <span style="color:rgb(79,129,135)">random</span>.<span style="color:rgb(79,129,135)">first</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">let</span> resultB = <span style="color:rgb(79,129,135)">random</span>.<span style="color:rgb(79,129,135)">first</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">let</span> resultC = <span style="color:rgb(112,61,170)">Array</span>(<span style="color:rgb(79,129,135)">random</span>.<span style="color:rgb(61,29,129)">prefix</span>(<span style="color:rgb(39,42,216)">4</span>))</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">let</span> resultD = <span style="color:rgb(112,61,170)">Array</span>(<span style="color:rgb(79,129,135)">random</span>.<span style="color:rgb(61,29,129)">prefix</span>(<span style="color:rgb(39,42,216)">4</span>))</p><div><br></div><div>all should agree that resultC and resultD will get different array. what&#39;s about with resultA and resultB?</div><div style="direction:ltr"><blockquote type="cite"><div>Gwendal Roué &lt;<a href="mailto:gwendal.roue@gmail.com" target="_blank">gwendal.roue@gmail.com</a>&gt; 於 2016年1月2日 下午8:13 寫道:</div><br><div><div>Hello,<br><br>My two cents: I feel uncomfortable with SequenceType.first since SequenceType clearly states that it may be destructed on iteration.<br><br>Compare :<br><br>seq.generate().next() // clear that it may give another result if called twice<br>seq.first             // unclear that it may give another result if called twice<br><br>Gwendal<br><br></div></div></blockquote></div><br></div></div></div>