<div dir="ltr">And we should better make chunks of 24 bits with current generator !!!<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/4/23  <span dir="ltr">&lt;<a href="mailto:commits@source.squeak.org" target="_blank">commits@source.squeak.org</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Nicolas Cellier uploaded a new version of Kernel to project The Inbox:<br>
<a href="http://source.squeak.org/inbox/Kernel-nice.754.mcz" target="_blank">http://source.squeak.org/inbox/Kernel-nice.754.mcz</a><br>
<br>
==================== Summary ====================<br>
<br>
Name: Kernel-nice.754<br>
Author: nice<br>
Time: 23 April 2013, 1:35:44.22 am<br>
UUID: 6525e6a7-e2f0-4b62-87e1-38915e225671<br>
Ancestors: Kernel-fbs.753<br>
<br>
Quick workaround to generate a large random with a poor generator.<br>
<br>
Notably, anything above 53 bits will be biased.<br>
Moreover, asking 309 decimal digits or more will overflow a double.<br>
<br>
THIS DESERVES MORE THOUGHTS:<br>
The workaround should better be handled in the generator itself...<br>
<br>
=============== Diff against Kernel-fbs.753 ===============<br>
<br>
Item was added:<br>
+ ----- Method: LargePositiveInteger&gt;&gt;atRandom: (in category &#39;truncation and round off&#39;) -----<br>
+ atRandom: aGenerator<br>
+       &quot;Answer a random integer from 1 to self picked from aGenerator.&quot;<br>
+<br>
+       | h chunk n k head res nextBytes |<br>
+       (h := self highBit) &lt;= 48<br>
+               ifTrue: [^super atRandom: aGenerator].<br>
+       chunk := 1 &lt;&lt; 48.<br>
+       res := self class new: self digitLength neg: false.<br>
+       n := h - 1 // 48.<br>
+       1 to: n do: [:i |<br>
+               nextBytes := (aGenerator nextInt: chunk) - 1.<br>
+               1 to: 6 do: [:j |<br>
+                       res digitAt: i - 1 * 6 + j put: (nextBytes digitAt: j)]].<br>
+<br>
+       k :=  h - (n * 48).<br>
+       chunk := 1 &lt;&lt; k.<br>
+       head := self &gt;&gt; (n * 48).<br>
+<br>
+       [(nextBytes := (aGenerator nextInt: chunk) - 1) &gt; head<br>
+               or:<br>
+                       [1 to: nextBytes digitLength do: [:j |<br>
+                               res digitAt: n * 6 + j put: (nextBytes digitAt: j)]].<br>
+                       res &gt;= self] whileTrue.<br>
+<br>
+       ^res + 1!<br>
<br>
<br>
</blockquote></div><br></div>