https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112021-09-21T22:26:53ZRuby Issue Tracking SystemRuby master - Feature #18183: make SecureRandom.choose publichttps://bugs.ruby-lang.org/issues/18183?journal_id=937752021-09-21T22:26:53Zolleicua (Antha Auciello)olleicua@gmail.com
<ul></ul><p>Pull request here: <a href="https://github.com/ruby/ruby/pull/4878" class="external">https://github.com/ruby/ruby/pull/4878</a></p> Ruby master - Feature #18183: make SecureRandom.choose publichttps://bugs.ruby-lang.org/issues/18183?journal_id=937812021-09-22T03:18:53Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-5 priority-4 priority-default closed" href="/issues/10849">Feature #10849</a>: Adding an alphanumeric function to SecureRandom</i> added</li></ul> Ruby master - Feature #18183: make SecureRandom.choose publichttps://bugs.ruby-lang.org/issues/18183?journal_id=950892021-12-03T06:52:45Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-5 priority-4 priority-default closed" href="/issues/18190">Feature #18190</a>: Split `Random::Formatter` from securerandom</i> added</li></ul> Ruby master - Feature #18183: make SecureRandom.choose publichttps://bugs.ruby-lang.org/issues/18183?journal_id=953992021-12-16T22:26:18Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>I agree with the proposal, but <code>choice</code> is not a good name for a public method.</p>
<p>Matz.</p> Ruby master - Feature #18183: make SecureRandom.choose publichttps://bugs.ruby-lang.org/issues/18183?journal_id=978392022-06-05T17:01:50Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Has duplicate</strong> <i><a class="issue tracker-2 status-6 priority-4 priority-default closed" href="/issues/18817">Feature #18817</a>: SecureRandom::choose is not being exposed</i> added</li></ul> Ruby master - Feature #18183: make SecureRandom.choose publichttps://bugs.ruby-lang.org/issues/18183?journal_id=978432022-06-06T03:28:41Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p><code>SecureRandom.choose(*args)</code> is not intuitive from my POV. Use <code>args.sample(random: SecureRandom)</code>.</p>
<p>Matz.</p> Ruby master - Feature #18183: make SecureRandom.choose publichttps://bugs.ruby-lang.org/issues/18183?journal_id=978442022-06-06T03:40:13Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>My bad. args.sample(random: SecureRandom) is not a replacement for SecureRandom.choose(*args,len).<br>
But still, choose does not describe the behavior.</p>
<p>Matz.</p> Ruby master - Feature #18183: make SecureRandom.choose publichttps://bugs.ruby-lang.org/issues/18183?journal_id=978452022-06-06T04:01:51Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/13">@matz (Yukihiro Matsumoto)</a> The OP proposed <code>random_string</code>. What do you think about it?</p> Ruby master - Feature #18183: make SecureRandom.choose publichttps://bugs.ruby-lang.org/issues/18183?journal_id=978482022-06-06T05:38:03Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>I don't think <code>SecureRandom.random_string(args, len)</code> describes the behavior, neither.</p>
<p>Matz.</p> Ruby master - Feature #18183: make SecureRandom.choose publichttps://bugs.ruby-lang.org/issues/18183?journal_id=978502022-06-06T16:45:18Zmidnight (Sarun R)
<ul></ul><p>My bad for not searching the old topics.<br>
In this module, (most of) the method name describes the output, not the procedure, not how to generate the output.</p>
<p>For example:<br>
Method <code>hex</code> outputs a hexadecimal number.<br>
Method <code>uuid</code> outputs a uuid.</p>
<p>The problem now is that what do we call this thing:<br>
"5FHY5PXLT184GIVISCVESTMGO"<br>
given that the characters come from a specific input set.</p>
<p>My naive self would call it a string, but it is not just any string; maybe, "string" with some adjective?</p>
<p>Otherwise, what I call straight from my business application is "code".<br>
<code>SecureRandom.code</code> maybe?</p> Ruby master - Feature #18183: make SecureRandom.choose publichttps://bugs.ruby-lang.org/issues/18183?journal_id=978532022-06-06T17:38:49Zaustin (Austin Ziegler)halostatue@gmail.com
<ul></ul><p>One option would be to extend <code>Random::Formatter#alphanumeric</code> to have an optional "alphabet":</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">def</span> <span class="nf">alphanumeric</span><span class="p">(</span><span class="n">n</span><span class="o">=</span><span class="kp">nil</span><span class="p">,</span> <span class="ss">alphabet: </span><span class="no">ALPHANUMERIC</span><span class="p">)</span>
<span class="n">n</span> <span class="o">=</span> <span class="mi">16</span> <span class="k">if</span> <span class="n">n</span><span class="p">.</span><span class="nf">nil?</span>
<span class="n">choose</span><span class="p">(</span><span class="n">alphabet</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="k">end</span>
</code></pre> Ruby master - Feature #18183: make SecureRandom.choose publichttps://bugs.ruby-lang.org/issues/18183?journal_id=979172022-06-09T19:13:15Zmidnight (Sarun R)
<ul></ul><p>In case we really can't agree on the name.<br>
I reimplement the functionality as an independent class on a GitHub's Gist; without using non-public API and the <code>send</code> hack, of course.</p>
<p><a href="https://gist.github.com/midnight-wonderer/8fec1c670bd07f26b9466010842d2421" class="external">https://gist.github.com/midnight-wonderer/8fec1c670bd07f26b9466010842d2421</a></p>
<p>Usage:</p>
<pre><code class="Ruby syntaxhl" data-language="Ruby"><span class="n">code_generator</span> <span class="o">=</span> <span class="no">RandomCode</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="ss">choose_from: </span><span class="p">(</span><span class="s1">'A'</span><span class="o">..</span><span class="s1">'Z'</span><span class="p">).</span><span class="nf">to_a</span><span class="p">)</span>
<span class="n">code_generator</span><span class="p">.</span><span class="nf">call</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
</code></pre>
<p>It would be better if the functionality is in the core, though.</p> Ruby master - Feature #18183: make SecureRandom.choose publichttps://bugs.ruby-lang.org/issues/18183?journal_id=979652022-06-14T02:40:48Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>austin (Austin Ziegler) wrote in <a href="#note-11">#note-11</a>:</p>
<blockquote>
<p>One option would be to extend <code>Random::Formatter#alphanumeric</code> to have an optional "alphabet":</p>
</blockquote>
<p>This approach looks nice to me. If "numeric" sounds a bit weird here, how about introducing <code>Random::Formatter#alphabet(n = 16, alphabet: [*'A'..'Z', *'a'..'z'])</code>?</p> Ruby master - Feature #18183: make SecureRandom.choose publichttps://bugs.ruby-lang.org/issues/18183?journal_id=979662022-06-14T03:25:19Zaustin (Austin Ziegler)halostatue@gmail.com
<ul></ul><p>mame (Yusuke Endoh) wrote in <a href="#note-13">#note-13</a>:</p>
<blockquote>
<p>austin (Austin Ziegler) wrote in <a href="#note-11">#note-11</a>:</p>
<blockquote>
<p>One option would be to extend <code>Random::Formatter#alphanumeric</code> to have an optional "alphabet":</p>
</blockquote>
<p>This approach looks nice to me. If "numeric" sounds a bit weird here, how about introducing <code>Random::Formatter#alphabet(n = 16, alphabet: [*'A'..'Z', *'a'..'z'])</code>?</p>
</blockquote>
<p>I think that <code>#alphanumeric</code> might still be the better name as the alphabet could be <code>[*'ABCDFGHKMNPQRTUVWXYZ'.split(''), *'0'..'9']</code>. If that’s not preferred, there are two choices, I think:</p>
<ul>
<li><code>Random::Formatter#alphanumeric(n = 16, set: …)</code></li>
<li>
<code>Random::Formatter#from_set(set, n = 16)</code> (or <code>Random::Formatter#from_set(n = 16, set: …)</code>)</li>
</ul>
<p>I think that <code>alphabet</code> is still the right word here, as it’s sort of the "term of art" for this sort of thing, although <code>set</code> is probably a good name as well. In any case, there should be a recommendation that the <code>alphabet</code> or the <code>set</code> parameter for any of these be a constant frozen value and not a localized constructed value.</p> Ruby master - Feature #18183: make SecureRandom.choose publichttps://bugs.ruby-lang.org/issues/18183?journal_id=979672022-06-14T03:31:13Zolleicua (Antha Auciello)olleicua@gmail.com
<ul></ul><blockquote>
<ul>
<li>
<code>Random::Formatter#from_set(set, n = 16)</code> (or <code>Random::Formatter#from_set(n = 16, set: …)</code>)</li>
</ul>
</blockquote>
<p>I like <code>Random::Formatter#from_set</code> or <code>Random::Formatter#from_alphabet</code> because <code>from</code> makes it clear what the purpose of the additional parameter is.</p>
<p><code>Random::Formatter#alphabet</code> would seem a little confusing to me as it could suggest that a standard <code>a-z</code> alphabet of some sort is being used.</p> Ruby master - Feature #18183: make SecureRandom.choose publichttps://bugs.ruby-lang.org/issues/18183?journal_id=980492022-06-16T07:54:24Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>I prefer <code>Random::Formatter#alphanumeric(n = 16, chars: …)</code> to others. But <code>alphabet:</code> or <code>set:</code> are acceptable too.</p>
<p>Matz.</p> Ruby master - Feature #18183: make SecureRandom.choose publichttps://bugs.ruby-lang.org/issues/18183?journal_id=1006592022-12-15T08:00:49Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Rejected</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>nobu (Nobuyoshi Nakada)</i></li></ul> Ruby master - Feature #18183: make SecureRandom.choose publichttps://bugs.ruby-lang.org/issues/18183?journal_id=1043842023-08-28T23:43:47Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Has duplicate</strong> <i><a class="issue tracker-2 status-5 priority-4 priority-default closed" href="/issues/19854">Feature #19854</a>: Make SecureRandom.choose public</i> added</li></ul> Ruby master - Feature #18183: make SecureRandom.choose publichttps://bugs.ruby-lang.org/issues/18183?journal_id=1043862023-08-29T02:21:30Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p><a href="https://github.com/ruby/ruby/pull/8312" class="external">https://github.com/ruby/ruby/pull/8312</a></p> Ruby master - Feature #18183: make SecureRandom.choose publichttps://bugs.ruby-lang.org/issues/18183?journal_id=1043892023-08-29T04:50:44Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="[Feature #18183] Add `chars:` option to `Random#alphanumeric`" href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/7e5c662a6f2e8435f8103bc16185bed6759cc557">git|7e5c662a6f2e8435f8103bc16185bed6759cc557</a>.</p>
<hr>
<p>[Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: make SecureRandom.choose public (Closed)" href="https://bugs.ruby-lang.org/issues/18183">#18183</a>] Add <code>chars:</code> option to <code>Random#alphanumeric</code></p>