<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3357: [fund.ts.v3] default_random_engine is overspecified for per-thread engine</title>
<meta property="og:title" content="Issue 3357: [fund.ts.v3] default_random_engine is overspecified for per-thread engine">
<meta property="og:description" content="C++ library issue. Status: Open">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3357.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#Open">Open</a> status.</em></p>
<h3 id="3357"><a href="lwg-active.html#3357">3357</a>. [fund.ts.v3] <code>default_random_engine</code> is overspecified for per-thread engine</h3>
<p><b>Section:</b> 99 <a href="https://cplusplus.github.io/fundamentals-ts/v3.html#rand.util.randint">[fund.ts.v3::rand.util.randint]</a> <b>Status:</b> <a href="lwg-active.html#Open">Open</a>
 <b>Submitter:</b> Zhihao Yuan <b>Opened:</b> 2019-12-10 <b>Last modified:</b> 2022-11-30</p>
<p><b>Priority: </b>3
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Open">Open</a> status.</p>
<p><b>Discussion:</b></p>
<p><b>Addresses: fund.ts.v3</b></p>
<p>
Although "implementation may select this type on the basis of performance, size,
quality, or any combination of such factors," but changing this typedef is an ABI-break
for implementations. Specifying per-thread engine to use this typedef results in losses
of performance, size, and/or quality.
<p/>
Since this type is not involved in <code>randint</code> facilities' interface (other than its member
typedef), the current specification should be relaxed.
</p>

<p><i>[2020-01 Priority set to 3 and assigned to LEWG after review on the reflector.]</i></p>


<p><i>[2020-05-28; LEWG issue reviewing]</i></p>

<p>
LEWG issue processing voted to reject 3357 as NAD. Status change to Open.
</p>
<blockquote>
<pre>
Reject LWG3357 as NAD

SF  F N A SA
1  10 4 2 1
</pre>
</blockquote>

<p><i>[2022-10-19; Reflector poll]</i></p>

<p>
Set status to "Tentatively NAD" based on LEWG recommendation and reflector poll.
</p>

<p><i>[2022-11-30; LWG telecon]</i></p>

<p>
Prefer to keep an open issue for the TS than to possibly forget to address it
if this feature is proposed for the IS some day.
</p>



<p id="res-3357"><b>Proposed resolution:</b></p>
<p>This wording is relative to <a href="https://wg21.link/n4840">N4840</a>.</p>

<ol>
<li><p>Modify 11.1.1 <a href="https://cplusplus.github.io/fundamentals-ts/v3.html#rand.syn">[fund.ts.v3::rand.syn]</a>, header <code>&lt;experimental/random&gt;</code> synopsis, as indicated:</p>

<blockquote>
<pre>
#include &lt;random&gt;

namespace std::experimental {
inline namespace fundamentals_v3 {

  <i>// 10.1.2.1, Function template randint</i>
  template &lt;class IntType&gt;
  IntType randint(IntType a, IntType b);
  void reseed();
  void reseed(<del>default_random_engine::result_type</del><ins>uint_fast32_t</ins> value);

} // inline namespace fundamentals_v3
} // namespace std::experimental
</pre>
</blockquote>
</li>

<li><p>Modify 99 <a href="https://cplusplus.github.io/fundamentals-ts/v3.html#rand.util.randint">[fund.ts.v3::rand.util.randint]</a> as indicated:</p>

<blockquote>
<p>
-1- A separate <i>per-thread engine</i> of <del>type <code>default_random_engine</code> 
(C++17 &sect;29.6.5)</del><ins>unspecified type that meets the requirements of random 
number engine (C++17 [rand.req.eng])</ins>, initialized to an unpredictable state, 
shall be maintained for each thread. <ins>[<i>Note:</i> The implementation may choose 
the engine type on the basis of performance, size, quality, or any combination of such 
factors, so as to provide at least acceptable engine behavior for relatively casual, 
inexpert, and/or lightweight use. &mdash; <i>end note</i>]</ins>
</p>
[&hellip;]
<pre>
void reseed();
void reseed(<del>default_random_engine::result_type</del><ins>uint_fast32_t</ins> value);
</pre>
<blockquote>
<p>
-7- <i>Effects:</i> Let <code>g</code> be the per-thread engine. The first form sets <code>g</code> to an unpredictable 
state. The second form invokes <code>g.seed(value)</code>.
<p/>
-8- <i>Postconditions:</i> Subsequent calls to <code>randint</code> do not depend on values produced by <code>g</code> 
before calling reseed. [<i>Note:</i> <code>reseed</code> also resets any instances of 
<code>uniform_int_distribution</code> used by <code>randint</code>. &mdash; <i>end note</i>] 
</p>
</blockquote>
</blockquote>
</li>

</ol>




</body>
</html>
