Skip to content

Commit 450f5d9

Browse files
committed
doc: add math/rand/v2 release notes
Change-Id: If1922413ff948f9b8d8cebec6756b6870f38c162 Reviewed-on: https://go-review.googlesource.com/c/go/+/550777 Reviewed-by: David Chase <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 08bec0d commit 450f5d9

File tree

1 file changed

+79
-30
lines changed

1 file changed

+79
-30
lines changed

doc/go1.22.html

Lines changed: 79 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -274,40 +274,89 @@ <h2 id="library">Core library</h2>
274274

275275
<h3 id="math_rand_v2">New math/rand/v2 package</h3>
276276

277-
<p><!-- CL 502495 -->
278-
TODO: <a href="https://go.dev/cl/502495">https://go.dev/cl/502495</a>: math/rand/v2: start of new API; modified api/next/61716.txt
279-
</p>
280-
281-
<p><!-- CL 502497 -->
282-
TODO: <a href="https://go.dev/cl/502497">https://go.dev/cl/502497</a>: math/rand/v2: remove Read; modified api/next/61716.txt
283-
</p>
284-
285-
<p><!-- CL 502498 -->
286-
TODO: <a href="https://go.dev/cl/502498">https://go.dev/cl/502498</a>: math/rand/v2: remove Rand.Seed; modified api/next/61716.txt
287-
</p>
288-
289-
<p><!-- CL 502499 -->
290-
TODO: <a href="https://go.dev/cl/502499">https://go.dev/cl/502499</a>: math/rand/v2: change Source to use uint64; modified api/next/61716.txt
291-
</p>
292-
293-
<p><!-- CL 502500 -->
294-
TODO: <a href="https://go.dev/cl/502500">https://go.dev/cl/502500</a>: math/rand/v2: add, optimize N, UintN, Uint32N, Uint64N; modified api/next/61716.txt
295-
</p>
296-
297-
<p><!-- CL 502505 -->
298-
TODO: <a href="https://go.dev/cl/502505">https://go.dev/cl/502505</a>: math/rand/v2: add PCG-DXSM; modified api/next/61716.txt
299-
</p>
277+
<!-- CL 502495 -->
278+
<!-- CL 502497 -->
279+
<!-- CL 502498 -->
280+
<!-- CL 502499 -->
281+
<!-- CL 502500 -->
282+
<!-- CL 502505 -->
283+
<!-- CL 502506 -->
284+
<!-- CL 516857 -->
285+
<!-- CL 516859 -->
300286

301-
<p><!-- CL 502506 -->
302-
TODO: <a href="https://go.dev/cl/502506">https://go.dev/cl/502506</a>: math/rand/v2: delete Mitchell/Reeds source; modified api/next/61716.txt
287+
<p>
288+
Go 1.22 includes the first “v2” package in the standard library,
289+
<a href="/pkg/math/rand/v2/"><code>math/rand/v2</code></a>.
290+
The changes compared to <a href="/pkg/math/rand/"><code>math/rand</code></a> are
291+
detailed in <a href="/issue/61716">proposal #61716</a>. The most important changes are:
303292
</p>
304293

305-
<p><!-- CL 516857 -->
306-
TODO: <a href="https://go.dev/cl/516857">https://go.dev/cl/516857</a>: math/rand/v2: rename various functions; modified api/next/61716.txt
307-
</p>
294+
<ul>
295+
<li>The <code>Read</code> method, deprecated in <code>math/rand</code>,
296+
was not carried forward for <code>math/rand/v2</code>.
297+
(It remains available in <code>math/rand</code>.)
298+
The vast majority of calls to <code>Read</code> should use
299+
<a href="/pkg/crypto/rand/#Read"><code>crypto/rand</code>’s <code>Read</code></a> instead.
300+
Otherwise a custom <code>Read</code> can be constructed using the <code>Uint64</code> method.
301+
302+
<li>The global generator accessed by top-level functions is unconditionally randomly seeded.
303+
Because the API guarantees no fixed sequence of results,
304+
optimizations like per-thread random generator states are now possible.
305+
306+
<li>The <a href="/pkg/math/rand/v2/#Source"><code>Source</code></a>
307+
interface now has a single <code>Uint64</code> method;
308+
there is no <code>Source64</code> interface.
309+
310+
<li>Many methods now use faster algorithms that were not possible to adopt in <code>math/rand</code>
311+
because they changed the output streams.
312+
313+
<li>The
314+
<code>Intn</code>,
315+
<code>Int31</code>,
316+
<code>Int31n</code>,
317+
<code>Int63</code>,
318+
and
319+
<code>Int64n</code>
320+
top-level functions and methods from <code>math/rand</code>
321+
are spelled more idiomatically in <code>math/rand/v2</code>:
322+
<code>IntN</code>,
323+
<code>Int32</code>,
324+
<code>Int32N</code>,
325+
<code>Int64</code>,
326+
and
327+
<code>Int64N</code>.
328+
There are also new top-level functions and methods
329+
<code>Uint32</code>,
330+
<code>Uint32N</code>,
331+
<code>Uint64</code>,
332+
<code>Uint64N</code>,
333+
<code>Uint</code>,
334+
and
335+
<code>UintN</code>.
336+
337+
<li>The
338+
new generic function <a href="/pkg/math/rand/v2/#N"><code>N</code></a>
339+
is like
340+
<a href="/pkg/math/rand/v2/#Int64N"><code>Int64N</code></a> or
341+
<a href="/pkg/math/rand/v2/#Uint64N"><code>Uint64N</code></a>
342+
but works for any integer type.
343+
For example a random duration from 0 up to 5 minutes is
344+
<code>rand.N(5*time.Minute)</code>.
345+
346+
<li>The Mitchell & Reeds LFSR generator provided by
347+
<a href="/pkg/math/rand/#Source"><code>math/rand</code>’s <code>Source</code></a>
348+
has been replaced by two more modern pseudo-random generator sources:
349+
<a href="/pkg/math/rand/v2/#ChaCha8"><code>ChaCha8</code></a>
350+
<a href="/pkg/math/rand/v2/#PCG"><code>PCG</code></a>.
351+
ChaCha8 is a new, cryptographically strong random number generator
352+
roughly similar to PCG in efficiency.
353+
ChaCha8 is the algorithm used for the top-level functions in <code>math/rand/v2</code>.
354+
As of Go 1.22, <code>math/rand</code>'s top-level functions (when not explicitly seeded)
355+
and the Go runtime also use ChaCha8 for randomness.
356+
</ul>
308357

309-
<p><!-- CL 516859 -->
310-
TODO: <a href="https://go.dev/cl/516859">https://go.dev/cl/516859</a>: math/rand/v2: add ChaCha8; modified api/next/61716.txt
358+
<p>
359+
We plan to include an API migration tool in a future release, likely Go 1.23.
311360
</p>
312361

313362
<h3 id="minor_library_changes">Minor changes to the library</h3>

0 commit comments

Comments
 (0)