mirror of https://github.com/matrix-org/go-neb.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
942 lines
28 KiB
942 lines
28 KiB
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<meta name="theme-color" content="#375EAB">
|
|
|
|
<title>rand - The Go Programming Language</title>
|
|
|
|
<link type="text/css" rel="stylesheet" href="../../../lib/godoc/style.css">
|
|
|
|
<link rel="stylesheet" href="../../../lib/godoc/jquery.treeview.css">
|
|
<script type="text/javascript">window.initFuncs = [];</script>
|
|
</head>
|
|
<body>
|
|
|
|
<div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
|
|
...
|
|
</div><!-- #lowframe -->
|
|
|
|
<div id="topbar" class="wide"><div class="container">
|
|
<div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
|
|
<div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
|
|
<a href="index.html#" id="menu-button"><span id="menu-button-arrow">▽</span></a>
|
|
<form method="GET" action="http://localhost:6060/search">
|
|
<div id="menu">
|
|
<a href="http://localhost:6060/doc/">Documents</a>
|
|
<a href="http://localhost:6060/pkg/">Packages</a>
|
|
<a href="http://localhost:6060/project/">The Project</a>
|
|
<a href="http://localhost:6060/help/">Help</a>
|
|
<a href="http://localhost:6060/blog/">Blog</a>
|
|
|
|
<input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
|
|
</div>
|
|
</form>
|
|
|
|
</div></div>
|
|
|
|
|
|
|
|
<div id="page" class="wide">
|
|
<div class="container">
|
|
|
|
|
|
<h1>Package rand</h1>
|
|
|
|
|
|
|
|
|
|
<div id="nav"></div>
|
|
|
|
|
|
<!--
|
|
Copyright 2009 The Go Authors. All rights reserved.
|
|
Use of this source code is governed by a BSD-style
|
|
license that can be found in the LICENSE file.
|
|
-->
|
|
<!--
|
|
Note: Static (i.e., not template-generated) href and id
|
|
attributes start with "pkg-" to make it impossible for
|
|
them to conflict with generated attributes (some of which
|
|
correspond to Go identifiers).
|
|
-->
|
|
|
|
<script type='text/javascript'>
|
|
document.ANALYSIS_DATA = null;
|
|
document.CALLGRAPH = null;
|
|
</script>
|
|
|
|
|
|
|
|
<div id="short-nav">
|
|
<dl>
|
|
<dd><code>import "math/rand"</code></dd>
|
|
</dl>
|
|
<dl>
|
|
<dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
|
|
<dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
|
|
|
|
<dd><a href="index.html#pkg-examples" class="examplesLink">Examples</a></dd>
|
|
|
|
|
|
</dl>
|
|
</div>
|
|
<!-- The package's Name is printed as title by the top-level template -->
|
|
<div id="pkg-overview" class="toggleVisible">
|
|
<div class="collapsed">
|
|
<h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
|
|
</div>
|
|
<div class="expanded">
|
|
<h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
|
|
<p>
|
|
Package rand implements pseudo-random number generators.
|
|
</p>
|
|
<p>
|
|
Random numbers are generated by a Source. Top-level functions, such as
|
|
Float64 and Int, use a default shared Source that produces a deterministic
|
|
sequence of values each time a program is run. Use the Seed function to
|
|
initialize the default Source if different behavior is required for each run.
|
|
The default Source is safe for concurrent use by multiple goroutines.
|
|
</p>
|
|
<p>
|
|
For random numbers suitable for security-sensitive work, see the crypto/rand
|
|
package.
|
|
</p>
|
|
|
|
</div>
|
|
</div>
|
|
<div id="example_" class="toggle">
|
|
<div class="collapsed">
|
|
<p class="exampleHeading toggleButton">▹ <span class="text">Example</span></p>
|
|
</div>
|
|
<div class="expanded">
|
|
<p class="exampleHeading toggleButton">▾ <span class="text">Example</span></p>
|
|
|
|
|
|
|
|
<p>Code:</p>
|
|
<pre class="code">rand.Seed(42) <span class="comment">// Try changing this number!</span>
|
|
answers := []string{
|
|
"It is certain",
|
|
"It is decidedly so",
|
|
"Without a doubt",
|
|
"Yes definitely",
|
|
"You may rely on it",
|
|
"As I see it yes",
|
|
"Most likely",
|
|
"Outlook good",
|
|
"Yes",
|
|
"Signs point to yes",
|
|
"Reply hazy try again",
|
|
"Ask again later",
|
|
"Better not tell you now",
|
|
"Cannot predict now",
|
|
"Concentrate and ask again",
|
|
"Don't count on it",
|
|
"My reply is no",
|
|
"My sources say no",
|
|
"Outlook not so good",
|
|
"Very doubtful",
|
|
}
|
|
fmt.Println("Magic 8-Ball says:", answers[rand.Intn(len(answers))])
|
|
<span class="comment"></pre>
|
|
|
|
<p>Output:</p>
|
|
<pre class="output">Magic 8-Ball says: As I see it yes
|
|
</pre>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<div id="example__rand" class="toggle">
|
|
<div class="collapsed">
|
|
<p class="exampleHeading toggleButton">▹ <span class="text">Example (Rand)</span></p>
|
|
</div>
|
|
<div class="expanded">
|
|
<p class="exampleHeading toggleButton">▾ <span class="text">Example (Rand)</span></p>
|
|
<p>This example shows the use of each of the methods on a *Rand.
|
|
The use of the global functions is the same, without the receiver.
|
|
</p>
|
|
|
|
|
|
<p>Code:</p>
|
|
<pre class="code"><span class="comment">// Create and seed the generator.</span>
|
|
<span class="comment">// Typically a non-fixed seed should be used, such as time.Now().UnixNano().</span>
|
|
<span class="comment">// Using a fixed seed will produce the same output on every run.</span>
|
|
r := rand.New(rand.NewSource(99))
|
|
|
|
<span class="comment">// The tabwriter here helps us generate aligned output.</span>
|
|
w := tabwriter.NewWriter(os.Stdout, 1, 1, 1, ' ', 0)
|
|
defer w.Flush()
|
|
show := func(name string, v1, v2, v3 interface{}) {
|
|
fmt.Fprintf(w, "%s\t%v\t%v\t%v\n", name, v1, v2, v3)
|
|
}
|
|
|
|
<span class="comment">// Float32 and Float64 values are in [0, 1).</span>
|
|
show("Float32", r.Float32(), r.Float32(), r.Float32())
|
|
show("Float64", r.Float64(), r.Float64(), r.Float64())
|
|
|
|
<span class="comment">// ExpFloat64 values have an average of 1 but decay exponentially.</span>
|
|
show("ExpFloat64", r.ExpFloat64(), r.ExpFloat64(), r.ExpFloat64())
|
|
|
|
<span class="comment">// NormFloat64 values have an average of 0 and a standard deviation of 1.</span>
|
|
show("NormFloat64", r.NormFloat64(), r.NormFloat64(), r.NormFloat64())
|
|
|
|
<span class="comment">// Int31, Int63, and Uint32 generate values of the given width.</span>
|
|
<span class="comment">// The Int method (not shown) is like either Int31 or Int63</span>
|
|
<span class="comment">// depending on the size of 'int'.</span>
|
|
show("Int31", r.Int31(), r.Int31(), r.Int31())
|
|
show("Int63", r.Int63(), r.Int63(), r.Int63())
|
|
show("Uint32", r.Uint32(), r.Uint32(), r.Uint32())
|
|
|
|
<span class="comment">// Intn, Int31n, and Int63n limit their output to be < n.</span>
|
|
<span class="comment">// They do so more carefully than using r.Int()%n.</span>
|
|
show("Intn(10)", r.Intn(10), r.Intn(10), r.Intn(10))
|
|
show("Int31n(10)", r.Int31n(10), r.Int31n(10), r.Int31n(10))
|
|
show("Int63n(10)", r.Int63n(10), r.Int63n(10), r.Int63n(10))
|
|
|
|
<span class="comment">// Perm generates a random permutation of the numbers [0, n).</span>
|
|
show("Perm", r.Perm(5), r.Perm(5), r.Perm(5))
|
|
<span class="comment"></pre>
|
|
|
|
<p>Output:</p>
|
|
<pre class="output">Float32 0.2635776 0.6358173 0.6718283
|
|
Float64 0.628605430454327 0.4504798828572669 0.9562755949377957
|
|
ExpFloat64 0.3362240648200941 1.4256072328483647 0.24354758816173044
|
|
NormFloat64 0.17233959114940064 1.577014951434847 0.04259129641113857
|
|
Int31 1501292890 1486668269 182840835
|
|
Int63 3546343826724305832 5724354148158589552 5239846799706671610
|
|
Uint32 2760229429 296659907 1922395059
|
|
Intn(10) 1 2 5
|
|
Int31n(10) 4 7 8
|
|
Int63n(10) 7 6 3
|
|
Perm [1 4 2 3 0] [4 2 1 3 0] [1 2 4 0 3]
|
|
</pre>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div id="pkg-index" class="toggleVisible">
|
|
<div class="collapsed">
|
|
<h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
|
|
</div>
|
|
<div class="expanded">
|
|
<h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
|
|
|
|
<!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
|
|
<div id="manual-nav">
|
|
<dl>
|
|
|
|
|
|
|
|
|
|
<dd><a href="index.html#ExpFloat64">func ExpFloat64() float64</a></dd>
|
|
|
|
|
|
<dd><a href="index.html#Float32">func Float32() float32</a></dd>
|
|
|
|
|
|
<dd><a href="index.html#Float64">func Float64() float64</a></dd>
|
|
|
|
|
|
<dd><a href="index.html#Int">func Int() int</a></dd>
|
|
|
|
|
|
<dd><a href="index.html#Int31">func Int31() int32</a></dd>
|
|
|
|
|
|
<dd><a href="index.html#Int31n">func Int31n(n int32) int32</a></dd>
|
|
|
|
|
|
<dd><a href="index.html#Int63">func Int63() int64</a></dd>
|
|
|
|
|
|
<dd><a href="index.html#Int63n">func Int63n(n int64) int64</a></dd>
|
|
|
|
|
|
<dd><a href="index.html#Intn">func Intn(n int) int</a></dd>
|
|
|
|
|
|
<dd><a href="index.html#NormFloat64">func NormFloat64() float64</a></dd>
|
|
|
|
|
|
<dd><a href="index.html#Perm">func Perm(n int) []int</a></dd>
|
|
|
|
|
|
<dd><a href="index.html#Read">func Read(p []byte) (n int, err error)</a></dd>
|
|
|
|
|
|
<dd><a href="index.html#Seed">func Seed(seed int64)</a></dd>
|
|
|
|
|
|
<dd><a href="index.html#Uint32">func Uint32() uint32</a></dd>
|
|
|
|
|
|
|
|
<dd><a href="index.html#Rand">type Rand</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#New">func New(src Source) *Rand</a></dd>
|
|
|
|
|
|
|
|
<dd> <a href="index.html#Rand.ExpFloat64">func (r *Rand) ExpFloat64() float64</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Rand.Float32">func (r *Rand) Float32() float32</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Rand.Float64">func (r *Rand) Float64() float64</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Rand.Int">func (r *Rand) Int() int</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Rand.Int31">func (r *Rand) Int31() int32</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Rand.Int31n">func (r *Rand) Int31n(n int32) int32</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Rand.Int63">func (r *Rand) Int63() int64</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Rand.Int63n">func (r *Rand) Int63n(n int64) int64</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Rand.Intn">func (r *Rand) Intn(n int) int</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Rand.NormFloat64">func (r *Rand) NormFloat64() float64</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Rand.Perm">func (r *Rand) Perm(n int) []int</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Rand.Read">func (r *Rand) Read(p []byte) (n int, err error)</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Rand.Seed">func (r *Rand) Seed(seed int64)</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#Rand.Uint32">func (r *Rand) Uint32() uint32</a></dd>
|
|
|
|
|
|
|
|
<dd><a href="index.html#Source">type Source</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#NewSource">func NewSource(seed int64) Source</a></dd>
|
|
|
|
|
|
|
|
|
|
<dd><a href="index.html#Zipf">type Zipf</a></dd>
|
|
|
|
|
|
<dd> <a href="index.html#NewZipf">func NewZipf(r *Rand, s float64, v float64, imax uint64) *Zipf</a></dd>
|
|
|
|
|
|
|
|
<dd> <a href="index.html#Zipf.Uint64">func (z *Zipf) Uint64() uint64</a></dd>
|
|
|
|
|
|
|
|
</dl>
|
|
</div><!-- #manual-nav -->
|
|
|
|
|
|
<div id="pkg-examples">
|
|
<h4>Examples</h4>
|
|
<dl>
|
|
|
|
<dd><a class="exampleLink" href="index.html#example_">Package</a></dd>
|
|
|
|
<dd><a class="exampleLink" href="index.html#example__rand">Package (Rand)</a></dd>
|
|
|
|
</dl>
|
|
</div>
|
|
|
|
|
|
|
|
<h4>Package files</h4>
|
|
<p>
|
|
<span style="font-size:90%">
|
|
|
|
<a href="http://localhost:6060/src/math/rand/exp.go">exp.go</a>
|
|
|
|
<a href="http://localhost:6060/src/math/rand/normal.go">normal.go</a>
|
|
|
|
<a href="http://localhost:6060/src/math/rand/rand.go">rand.go</a>
|
|
|
|
<a href="http://localhost:6060/src/math/rand/rng.go">rng.go</a>
|
|
|
|
<a href="http://localhost:6060/src/math/rand/zipf.go">zipf.go</a>
|
|
|
|
</span>
|
|
</p>
|
|
|
|
</div><!-- .expanded -->
|
|
</div><!-- #pkg-index -->
|
|
|
|
<div id="pkg-callgraph" class="toggle" style="display: none">
|
|
<div class="collapsed">
|
|
<h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
|
|
</div> <!-- .expanded -->
|
|
<div class="expanded">
|
|
<h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
|
|
<p>
|
|
In the call graph viewer below, each node
|
|
is a function belonging to this package
|
|
and its children are the functions it
|
|
calls—perhaps dynamically.
|
|
</p>
|
|
<p>
|
|
The root nodes are the entry points of the
|
|
package: functions that may be called from
|
|
outside the package.
|
|
There may be non-exported or anonymous
|
|
functions among them if they are called
|
|
dynamically from another package.
|
|
</p>
|
|
<p>
|
|
Click a node to visit that function's source code.
|
|
From there you can visit its callers by
|
|
clicking its declaring <code>func</code>
|
|
token.
|
|
</p>
|
|
<p>
|
|
Functions may be omitted if they were
|
|
determined to be unreachable in the
|
|
particular programs or tests that were
|
|
analyzed.
|
|
</p>
|
|
<!-- Zero means show all package entry points. -->
|
|
<ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
|
|
</div>
|
|
</div> <!-- #pkg-callgraph -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="ExpFloat64">func <a href="http://localhost:6060/src/math/rand/rand.go?s=8279:8304#L240">ExpFloat64</a></h2>
|
|
<pre>func ExpFloat64() <a href="../../builtin/index.html#float64">float64</a></pre>
|
|
<p>
|
|
ExpFloat64 returns an exponentially distributed float64 in the range
|
|
(0, +math.MaxFloat64] with an exponential distribution whose rate parameter
|
|
(lambda) is 1 and whose mean is 1/lambda (1) from the default Source.
|
|
To produce a distribution with a different rate parameter,
|
|
callers can adjust the output using:
|
|
</p>
|
|
<pre>sample = ExpFloat64() / desiredRateParameter
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Float32">func <a href="http://localhost:6060/src/math/rand/rand.go?s=7061:7083#L211">Float32</a></h2>
|
|
<pre>func Float32() <a href="../../builtin/index.html#float32">float32</a></pre>
|
|
<p>
|
|
Float32 returns, as a float32, a pseudo-random number in [0.0,1.0)
|
|
from the default Source.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Float64">func <a href="http://localhost:6060/src/math/rand/rand.go?s=6907:6929#L207">Float64</a></h2>
|
|
<pre>func Float64() <a href="../../builtin/index.html#float64">float64</a></pre>
|
|
<p>
|
|
Float64 returns, as a float64, a pseudo-random number in [0.0,1.0)
|
|
from the default Source.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Int">func <a href="http://localhost:6060/src/math/rand/rand.go?s=6210:6224#L188">Int</a></h2>
|
|
<pre>func Int() <a href="../../builtin/index.html#int">int</a></pre>
|
|
<p>
|
|
Int returns a non-negative pseudo-random int from the default Source.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Int31">func <a href="http://localhost:6060/src/math/rand/rand.go?s=6087:6105#L185">Int31</a></h2>
|
|
<pre>func Int31() <a href="../../builtin/index.html#int32">int32</a></pre>
|
|
<p>
|
|
Int31 returns a non-negative pseudo-random 31-bit integer as an int32
|
|
from the default Source.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Int31n">func <a href="http://localhost:6060/src/math/rand/rand.go?s=6572:6598#L198">Int31n</a></h2>
|
|
<pre>func Int31n(n <a href="../../builtin/index.html#int32">int32</a>) <a href="../../builtin/index.html#int32">int32</a></pre>
|
|
<p>
|
|
Int31n returns, as an int32, a non-negative pseudo-random number in [0,n)
|
|
from the default Source.
|
|
It panics if n <= 0.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Int63">func <a href="http://localhost:6060/src/math/rand/rand.go?s=5796:5814#L177">Int63</a></h2>
|
|
<pre>func Int63() <a href="../../builtin/index.html#int64">int64</a></pre>
|
|
<p>
|
|
Int63 returns a non-negative pseudo-random 63-bit integer as an int64
|
|
from the default Source.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Int63n">func <a href="http://localhost:6060/src/math/rand/rand.go?s=6383:6409#L193">Int63n</a></h2>
|
|
<pre>func Int63n(n <a href="../../builtin/index.html#int64">int64</a>) <a href="../../builtin/index.html#int64">int64</a></pre>
|
|
<p>
|
|
Int63n returns, as an int64, a non-negative pseudo-random number in [0,n)
|
|
from the default Source.
|
|
It panics if n <= 0.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Intn">func <a href="http://localhost:6060/src/math/rand/rand.go?s=6757:6777#L203">Intn</a></h2>
|
|
<pre>func Intn(n <a href="../../builtin/index.html#int">int</a>) <a href="../../builtin/index.html#int">int</a></pre>
|
|
<p>
|
|
Intn returns, as an int, a non-negative pseudo-random number in [0,n)
|
|
from the default Source.
|
|
It panics if n <= 0.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="NormFloat64">func <a href="http://localhost:6060/src/math/rand/rand.go?s=7834:7860#L230">NormFloat64</a></h2>
|
|
<pre>func NormFloat64() <a href="../../builtin/index.html#float64">float64</a></pre>
|
|
<p>
|
|
NormFloat64 returns a normally distributed float64 in the range
|
|
[-math.MaxFloat64, +math.MaxFloat64] with
|
|
standard normal distribution (mean = 0, stddev = 1)
|
|
from the default Source.
|
|
To produce a different normal distribution, callers can
|
|
adjust the output using:
|
|
</p>
|
|
<pre>sample = NormFloat64() * desiredStdDev + desiredMean
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Perm">func <a href="http://localhost:6060/src/math/rand/rand.go?s=7234:7256#L215">Perm</a></h2>
|
|
<pre>func Perm(n <a href="../../builtin/index.html#int">int</a>) []<a href="../../builtin/index.html#int">int</a></pre>
|
|
<p>
|
|
Perm returns, as a slice of n ints, a pseudo-random permutation of the integers [0,n)
|
|
from the default Source.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Read">func <a href="http://localhost:6060/src/math/rand/rand.go?s=7419:7457#L219">Read</a></h2>
|
|
<pre>func Read(p []<a href="../../builtin/index.html#byte">byte</a>) (n <a href="../../builtin/index.html#int">int</a>, err <a href="../../builtin/index.html#error">error</a>)</pre>
|
|
<p>
|
|
Read generates len(p) random bytes from the default Source and
|
|
writes them into p. It always returns len(p) and a nil error.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Seed">func <a href="http://localhost:6060/src/math/rand/rand.go?s=5646:5667#L173">Seed</a></h2>
|
|
<pre>func Seed(seed <a href="../../builtin/index.html#int64">int64</a>)</pre>
|
|
<p>
|
|
Seed uses the provided seed value to initialize the default Source to a
|
|
deterministic state. If Seed is not called, the generator behaves as
|
|
if seeded by Seed(1).
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Uint32">func <a href="http://localhost:6060/src/math/rand/rand.go?s=5933:5953#L181">Uint32</a></h2>
|
|
<pre>func Uint32() <a href="../../builtin/index.html#uint32">uint32</a></pre>
|
|
<p>
|
|
Uint32 returns a pseudo-random 32-bit value as a uint32
|
|
from the default Source.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Rand">type <a href="http://localhost:6060/src/math/rand/rand.go?s=1105:1137#L24">Rand</a></h2>
|
|
<pre>type Rand struct {
|
|
<span class="comment">// contains filtered or unexported fields</span>
|
|
}</pre>
|
|
<p>
|
|
A Rand is a source of random numbers.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="New">func <a href="http://localhost:6060/src/math/rand/rand.go?s=1234:1260#L30">New</a></h3>
|
|
<pre>func New(src <a href="index.html#Source">Source</a>) *<a href="index.html#Rand">Rand</a></pre>
|
|
<p>
|
|
New returns a new Rand that uses random values from src
|
|
to generate other random values.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Rand.ExpFloat64">func (*Rand) <a href="http://localhost:6060/src/math/rand/exp.go?s=765:800#L21">ExpFloat64</a></h3>
|
|
<pre>func (r *<a href="index.html#Rand">Rand</a>) ExpFloat64() <a href="../../builtin/index.html#float64">float64</a></pre>
|
|
<p>
|
|
ExpFloat64 returns an exponentially distributed float64 in the range
|
|
(0, +math.MaxFloat64] with an exponential distribution whose rate parameter
|
|
(lambda) is 1 and whose mean is 1/lambda (1).
|
|
To produce a distribution with a different rate parameter,
|
|
callers can adjust the output using:
|
|
</p>
|
|
<pre>sample = ExpFloat64() / desiredRateParameter
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Rand.Float32">func (*Rand) <a href="http://localhost:6060/src/math/rand/rand.go?s=4125:4157#L123">Float32</a></h3>
|
|
<pre>func (r *<a href="index.html#Rand">Rand</a>) Float32() <a href="../../builtin/index.html#float32">float32</a></pre>
|
|
<p>
|
|
Float32 returns, as a float32, a pseudo-random number in [0.0,1.0).
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Rand.Float64">func (*Rand) <a href="http://localhost:6060/src/math/rand/rand.go?s=3113:3145#L97">Float64</a></h3>
|
|
<pre>func (r *<a href="index.html#Rand">Rand</a>) Float64() <a href="../../builtin/index.html#float64">float64</a></pre>
|
|
<p>
|
|
Float64 returns, as a float64, a pseudo-random number in [0.0,1.0).
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Rand.Int">func (*Rand) <a href="http://localhost:6060/src/math/rand/rand.go?s=1872:1896#L45">Int</a></h3>
|
|
<pre>func (r *<a href="index.html#Rand">Rand</a>) Int() <a href="../../builtin/index.html#int">int</a></pre>
|
|
<p>
|
|
Int returns a non-negative pseudo-random int.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Rand.Int31">func (*Rand) <a href="http://localhost:6060/src/math/rand/rand.go?s=1759:1787#L42">Int31</a></h3>
|
|
<pre>func (r *<a href="index.html#Rand">Rand</a>) Int31() <a href="../../builtin/index.html#int32">int32</a></pre>
|
|
<p>
|
|
Int31 returns a non-negative pseudo-random 31-bit integer as an int32.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Rand.Int31n">func (*Rand) <a href="http://localhost:6060/src/math/rand/rand.go?s=2478:2514#L69">Int31n</a></h3>
|
|
<pre>func (r *<a href="index.html#Rand">Rand</a>) Int31n(n <a href="../../builtin/index.html#int32">int32</a>) <a href="../../builtin/index.html#int32">int32</a></pre>
|
|
<p>
|
|
Int31n returns, as an int32, a non-negative pseudo-random number in [0,n).
|
|
It panics if n <= 0.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Rand.Int63">func (*Rand) <a href="http://localhost:6060/src/math/rand/rand.go?s=1503:1531#L36">Int63</a></h3>
|
|
<pre>func (r *<a href="index.html#Rand">Rand</a>) Int63() <a href="../../builtin/index.html#int64">int64</a></pre>
|
|
<p>
|
|
Int63 returns a non-negative pseudo-random 63-bit integer as an int64.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Rand.Int63n">func (*Rand) <a href="http://localhost:6060/src/math/rand/rand.go?s=2085:2121#L52">Int63n</a></h3>
|
|
<pre>func (r *<a href="index.html#Rand">Rand</a>) Int63n(n <a href="../../builtin/index.html#int64">int64</a>) <a href="../../builtin/index.html#int64">int64</a></pre>
|
|
<p>
|
|
Int63n returns, as an int64, a non-negative pseudo-random number in [0,n).
|
|
It panics if n <= 0.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Rand.Intn">func (*Rand) <a href="http://localhost:6060/src/math/rand/rand.go?s=2867:2897#L86">Intn</a></h3>
|
|
<pre>func (r *<a href="index.html#Rand">Rand</a>) Intn(n <a href="../../builtin/index.html#int">int</a>) <a href="../../builtin/index.html#int">int</a></pre>
|
|
<p>
|
|
Intn returns, as an int, a non-negative pseudo-random number in [0,n).
|
|
It panics if n <= 0.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Rand.NormFloat64">func (*Rand) <a href="http://localhost:6060/src/math/rand/normal.go?s=804:840#L28">NormFloat64</a></h3>
|
|
<pre>func (r *<a href="index.html#Rand">Rand</a>) NormFloat64() <a href="../../builtin/index.html#float64">float64</a></pre>
|
|
<p>
|
|
NormFloat64 returns a normally distributed float64 in the range
|
|
[-math.MaxFloat64, +math.MaxFloat64] with
|
|
standard normal distribution (mean = 0, stddev = 1).
|
|
To produce a different normal distribution, callers can
|
|
adjust the output using:
|
|
</p>
|
|
<pre>sample = NormFloat64() * desiredStdDev + desiredMean
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Rand.Perm">func (*Rand) <a href="http://localhost:6060/src/math/rand/rand.go?s=4585:4617#L136">Perm</a></h3>
|
|
<pre>func (r *<a href="index.html#Rand">Rand</a>) Perm(n <a href="../../builtin/index.html#int">int</a>) []<a href="../../builtin/index.html#int">int</a></pre>
|
|
<p>
|
|
Perm returns, as a slice of n ints, a pseudo-random permutation of the integers [0,n).
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Rand.Read">func (*Rand) <a href="http://localhost:6060/src/math/rand/rand.go?s=5159:5207#L153">Read</a></h3>
|
|
<pre>func (r *<a href="index.html#Rand">Rand</a>) Read(p []<a href="../../builtin/index.html#byte">byte</a>) (n <a href="../../builtin/index.html#int">int</a>, err <a href="../../builtin/index.html#error">error</a>)</pre>
|
|
<p>
|
|
Read generates len(p) random bytes and writes them into p. It
|
|
always returns len(p) and a nil error.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Rand.Seed">func (*Rand) <a href="http://localhost:6060/src/math/rand/rand.go?s=1375:1406#L33">Seed</a></h3>
|
|
<pre>func (r *<a href="index.html#Rand">Rand</a>) Seed(seed <a href="../../builtin/index.html#int64">int64</a>)</pre>
|
|
<p>
|
|
Seed uses the provided seed value to initialize the generator to a deterministic state.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Rand.Uint32">func (*Rand) <a href="http://localhost:6060/src/math/rand/rand.go?s=1618:1648#L39">Uint32</a></h3>
|
|
<pre>func (r *<a href="index.html#Rand">Rand</a>) Uint32() <a href="../../builtin/index.html#uint32">uint32</a></pre>
|
|
<p>
|
|
Uint32 returns a pseudo-random 32-bit value as a uint32.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Source">type <a href="http://localhost:6060/src/math/rand/rand.go?s=840:898#L11">Source</a></h2>
|
|
<pre>type Source interface {
|
|
Int63() <a href="../../builtin/index.html#int64">int64</a>
|
|
Seed(seed <a href="../../builtin/index.html#int64">int64</a>)
|
|
}</pre>
|
|
<p>
|
|
A Source represents a source of uniformly-distributed
|
|
pseudo-random int64 values in the range [0, 1<<63).
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="NewSource">func <a href="http://localhost:6060/src/math/rand/rand.go?s=977:1010#L17">NewSource</a></h3>
|
|
<pre>func NewSource(seed <a href="../../builtin/index.html#int64">int64</a>) <a href="index.html#Source">Source</a></pre>
|
|
<p>
|
|
NewSource returns a new pseudo-random Source seeded with the given value.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h2 id="Zipf">type <a href="http://localhost:6060/src/math/rand/zipf.go?s=411:627#L5">Zipf</a></h2>
|
|
<pre>type Zipf struct {
|
|
<span class="comment">// contains filtered or unexported fields</span>
|
|
}</pre>
|
|
<p>
|
|
A Zipf generates Zipf distributed variates.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="NewZipf">func <a href="http://localhost:6060/src/math/rand/zipf.go?s=1024:1086#L29">NewZipf</a></h3>
|
|
<pre>func NewZipf(r *<a href="index.html#Rand">Rand</a>, s <a href="../../builtin/index.html#float64">float64</a>, v <a href="../../builtin/index.html#float64">float64</a>, imax <a href="../../builtin/index.html#uint64">uint64</a>) *<a href="index.html#Zipf">Zipf</a></pre>
|
|
<p>
|
|
NewZipf returns a Zipf variate generator.
|
|
The generator generates values k ∈ [0, imax]
|
|
such that P(k) is proportional to (v + k) ** (-s).
|
|
Requirements: s > 1 and v >= 1.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h3 id="Zipf.Uint64">func (*Zipf) <a href="http://localhost:6060/src/math/rand/zipf.go?s=1517:1547#L48">Uint64</a></h3>
|
|
<pre>func (z *<a href="index.html#Zipf">Zipf</a>) Uint64() <a href="../../builtin/index.html#uint64">uint64</a></pre>
|
|
<p>
|
|
Uint64 returns a value drawn from the Zipf distribution described
|
|
by the Zipf object.
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div id="footer">
|
|
Build version go1.6.<br>
|
|
Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
|
|
the content of this page is licensed under the
|
|
Creative Commons Attribution 3.0 License,
|
|
and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
|
|
<a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
|
|
<a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
|
|
</div>
|
|
|
|
</div><!-- .container -->
|
|
</div><!-- #page -->
|
|
|
|
<!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
|
|
<script type="text/javascript" src="../../../lib/godoc/jquery.js"></script>
|
|
<script type="text/javascript" src="../../../lib/godoc/jquery.treeview.js"></script>
|
|
<script type="text/javascript" src="../../../lib/godoc/jquery.treeview.edit.js"></script>
|
|
|
|
|
|
<script type="text/javascript" src="../../../lib/godoc/godocs.js"></script>
|
|
|
|
</body>
|
|
</html>
|
|
|