Clarify determinism of Go playground w.r.t. random numbers

Fixes #443
This commit is contained in:
Eli Bendersky 2022-09-22 07:05:32 -07:00
parent 00543ca6f7
commit cc804d764b
4 changed files with 18 additions and 7 deletions

View File

@ -32,7 +32,7 @@ func main() {
// produce the same sequence of numbers each time by default.
// To produce varying sequences, give it a seed that changes.
// Note that this is not safe to use for random numbers you
// intend to be secret, use `crypto/rand` for those.
// intend to be secret; use `crypto/rand` for those.
s1 := rand.NewSource(time.Now().UnixNano())
r1 := rand.New(s1)

View File

@ -1,2 +1,2 @@
f0f88939692a32975d902c94066537a6ba5ab96f
RaoKyUd9tgC
ea6a386e4e5602247b2203fa433d4419ff5a9489
Enb5uJEx0Bt

View File

@ -1,3 +1,8 @@
# Depending on where you run this sample, some of the
# generated numbers may be different. Note that on
# the Go playground seeding with `time.Now()` still
# produces deterministic results due to the way the
# playground is implemented.
$ go run random-numbers.go
81,87
0.6645600532184904

14
public/random-numbers generated
View File

@ -43,7 +43,7 @@ generation.</p>
</td>
<td class="code leading">
<a href="https://go.dev/play/p/RaoKyUd9tgC"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
<a href="https://go.dev/play/p/Enb5uJEx0Bt"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
<pre class="chroma"><span class="kn">package</span> <span class="nx">main</span>
</pre>
</td>
@ -127,7 +127,7 @@ other ranges, for example <code>5.0 &lt;= f' &lt; 10.0</code>.</p>
produce the same sequence of numbers each time by default.
To produce varying sequences, give it a seed that changes.
Note that this is not safe to use for random numbers you
intend to be secret, use <code>crypto/rand</code> for those.</p>
intend to be secret; use <code>crypto/rand</code> for those.</p>
</td>
<td class="code leading">
@ -184,11 +184,17 @@ produces the same sequence of random numbers.</p>
<tr>
<td class="docs">
<p>Depending on where you run this sample, some of the
generated numbers may be different. Note that on
the Go playground seeding with <code>time.Now()</code> still
produces deterministic results due to the way the
playground is implemented.</p>
</td>
<td class="code leading">
<pre class="chroma"><span class="gp">$</span> go run random-numbers.go
<pre class="chroma">
<span class="gp">$</span> go run random-numbers.go
<span class="go">81,87
</span><span class="go">0.6645600532184904
</span><span class="go">7.123187485356329,8.434115364335547