https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112010-04-03T10:53:55ZRuby Issue Tracking SystemRuby master - Bug #3027: Random#rand(nil)https://bugs.ruby-lang.org/issues/3027?journal_id=97242010-04-03T10:53:55Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>=begin<br>
Hi,</p>
<p>At Sun, 28 Mar 2010 09:06:57 +0900,<br>
Marc-Andre Lafortune wrote in <a href="/issues/3027">[ruby-core:29075]</a>:</p>
<blockquote>
<p>Looking at Random#rand, I notice that passing nil has the<br>
same result as not passing any argument.</p>
</blockquote>
<p>It comes from Kernel#rand.</p>
<blockquote>
<p>Either it should raise an ArgumentError like the<br>
documentation implies, or else the documentation should be<br>
modified.</p>
<p>I would argue to raise an error because:</p>
<ul>
<li>it is easy to pass nothing, or pass 1.0 instead, and get<br>
the same result if that is what is desired</li>
<li>it could hide an error in the code, where the result is<br>
unexpectedly nil but the programmer didn't think about it<br>
(like whiny nils in rails)</li>
</ul>
</blockquote>
<p>Agreed. For the backward compatibility, I'll keep Kernel#rand<br>
and added the documentation instead.</p>
<p>--<br>
Nobu Nakada</p>
<p>=end</p> Ruby master - Bug #3027: Random#rand(nil)https://bugs.ruby-lang.org/issues/3027?journal_id=97252010-04-03T10:57:17Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>=begin<br>
This issue was solved with changeset r27204.<br>
Marc-Andre, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<p>=end</p>