<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 729: Problem in [rand.req.eng]/3</title>
<meta property="og:title" content="Issue 729: Problem in [rand.req.eng]/3">
<meta property="og:description" content="C++ library issue. Status: NAD">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue729.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#NAD">NAD</a> status.</em></p>
<h3 id="729"><a href="lwg-closed.html#729">729</a>. Problem in [rand.req.eng]/3</h3>
<p><b>Section:</b> 29.5.3.4 <a href="https://wg21.link/rand.req.eng">[rand.req.eng]</a> <b>Status:</b> <a href="lwg-active.html#NAD">NAD</a>
 <b>Submitter:</b> Stephan Tolksdorf <b>Opened:</b> 2007-09-21 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#rand.req.eng">issues</a> in [rand.req.eng].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD">NAD</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The 3rd table row in 29.5.3.4 <a href="https://wg21.link/rand.req.eng">[rand.req.eng]</a>/3 requires random number engines to accept any 
arithmetic type as a seed, which is then casted to the engine's <code>result_type</code> and subsequently 
used for seeding the state of the engine. The requirement stated as "Creates an engine with 
initial state determined by <code>static_cast&lt;X::result_type&gt;(s)</code>" forces random number engines 
to either use a seeding method that completely depends on the <code>result_type</code> (see the discussion 
of seeding for the <code>mersenne_twister_engine</code> in point T2 above) or at least to throw away "bits 
of randomness" in the seed value if the <code>result_type</code> is smaller than the seed type. This seems 
to be inappropriate for many modern random number generators, in particular F2-linear or 
cryptographic ones, which operate on an internal bit array that in principle is independent of the 
type of numbers returned.
</p>

<p>
<b>Possible resolution:</b> I propose to change the wording to a version similar to "Creates an 
engine with initial state determined by <code>static_cast&lt;UintType&gt;(s)</code>, where <code>UintType</code> is an 
implementation specific unsigned integer type."
</p>

<p>
Additionally, the definition of s in 29.5.3.4 <a href="https://wg21.link/rand.req.eng">[rand.req.eng]</a>/1 c) could be restricted to unsigned integer types.
</p>

<p>
Similarly, the type of the seed in 29.5.3.5 <a href="https://wg21.link/rand.req.adapt">[rand.req.adapt]</a>/3 e) could be left unspecified.
</p>

<p>
See <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2424.pdf">N2424</a>
for further discussion.
</p>

<p><i>[
Stephan Tolksdorf adds pre-Bellevue:
]</i></p>


<blockquote>
<p>
In reply to the discussion in
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2424.pdf">N2424</a>
regarding this issue:
</p>
<p>
The descriptions of all engines and engine adaptors given in sections
29.5.4 <a href="https://wg21.link/rand.eng">[rand.eng]</a> and 29.5.5 <a href="https://wg21.link/rand.adapt">[rand.adapt]</a> already specify the concrete
types of the integer arguments for seeding. Hence, relaxing the general
requirement in 29.5.3.4 <a href="https://wg21.link/rand.req.eng">[rand.req.eng]</a> would not affect portability and
reproducibility of the standard library. Furthermore, it is not clear to
me what exactly the guarantee "with initial state determined by
<code>static_cast&lt;X::result_type&gt;(s)</code>" is useful for. On the other hand,
relaxing the requirement would allow developers to implement  other
random number engines that do not have to cast all arithmetic seed
arguments to their result_types.
</p>
</blockquote>

<p><i>[
Bellevue:
]</i></p>


<blockquote><p>
Propose close NAD for the reasons given in N2424.
</p></blockquote>




<p id="res-729"><b>Proposed resolution:</b></p>
<p>
See <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2424.pdf">N2424</a>
for further discussion.
</p>

<p><i>[
Stephan Tolksdorf adds pre-Bellevue:
]</i></p>


<blockquote>
<p>
Change row 3 of table 105 "Random number engine requirements" in 29.5.3.4 <a href="https://wg21.link/rand.req.eng">[rand.req.eng]</a>/3
</p>

<blockquote><p>
Creates an engine with initial state determined by
<code><del>static_cast&lt;X::result_type&gt;(</del>s<del>)</del></code>
</p></blockquote>

<p>
Similarly, change 29.5.3.5 <a href="https://wg21.link/rand.req.adapt">[rand.req.adapt]</a>/3 e)
</p>

<blockquote><p>
When <code>X::X</code> is invoked with <del>an <code>X::result_type</code></del> value <code>s</code>
<ins>of arithmetic type (3.9.1)</ins>, ...
</p></blockquote>

</blockquote>






</body>
</html>
