Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9a3d75e1
Commit
9a3d75e1
authored
Feb 02, 2001
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor markup adjustments.
parent
bd843edf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
22 deletions
+26
-22
Doc/lib/librandom.tex
Doc/lib/librandom.tex
+26
-22
No files found.
Doc/lib/librandom.tex
View file @
9a3d75e1
...
@@ -34,15 +34,17 @@ Else, because no critical sections are implemented internally, calls
...
@@ -34,15 +34,17 @@ Else, because no critical sections are implemented internally, calls
from different threads may see the same return values.
from different threads may see the same return values.
The functions supplied by this module are actually bound methods of a
The functions supplied by this module are actually bound methods of a
hidden instance of the
\var
{
random.Random
}
class. You can instantiate your
hidden instance of the
\class
{
random.Random
}
class. You can
own instances of
\var
{
Random
}
to get generators that don't share state.
instantiate your own instances of
\class
{
Random
}
to get generators
This is especially useful for multi-threaded programs, creating a different
that don't share state. This is especially useful for multi-threaded
instance of
\var
{
Random
}
for each thread, and using the
\method
{
jumpahead()
}
programs, creating a different instance of
\class
{
Random
}
for each
method to ensure that the generated sequences seen by each thread don't
thread, and using the
\method
{
jumpahead()
}
method to ensure that the
overlap (see example below).
generated sequences seen by each thread don't overlap (see example
Class
\var
{
Random
}
can also be subclassed if you want to use a different
below).
basic generator of your own devising: in that case, override the
\method
{
random()
}
,
\method
{
seed()
}
,
\method
{
getstate()
}
,
Class
\class
{
Random
}
can also be subclassed if you want to use a
different basic generator of your own devising: in that case, override
the
\method
{
random()
}
,
\method
{
seed()
}
,
\method
{
getstate()
}
,
\method
{
setstate()
}
and
\method
{
jumpahead()
}
methods.
\method
{
setstate()
}
and
\method
{
jumpahead()
}
methods.
Here's one way to create threadsafe distinct and non-overlapping generators:
Here's one way to create threadsafe distinct and non-overlapping generators:
...
@@ -117,27 +119,29 @@ Bookkeeping functions:
...
@@ -117,27 +119,29 @@ Bookkeeping functions:
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
getstate
}{}
\begin{funcdesc}
{
getstate
}{}
Return an object capturing the current internal state of the generator.
Return an object capturing the current internal state of the
This object can be passed to
\code
{
setstate()
}
to restore the state.
generator. This object can be passed to
\function
{
setstate()
}
to
restore the state.
\versionadded
{
2.1
}
\versionadded
{
2.1
}
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
setstate
}{
state
}
\begin{funcdesc}
{
setstate
}{
state
}
\var
{
state
}
should have been obtained from a previous call to
\var
{
state
}
should have been obtained from a previous call to
\code
{
getstate()
}
, and
\code
{
setstate()
}
restores the internal state
\function
{
getstate()
}
, and
\function
{
setstate()
}
restores the
of the generator to what it was at the time
\code
{
setstate()
}
was called.
internal state of the generator to what it was at the time
\function
{
setstate()
}
was called.
\versionadded
{
2.1
}
\versionadded
{
2.1
}
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
jumpahead
}{
n
}
\begin{funcdesc}
{
jumpahead
}{
n
}
Change the internal state to what it would be if
\
code
{
random()
}
were
Change the internal state to what it would be if
\
function
{
random()
}
called n times, but do so quickly.
\var
{
n
}
is a non-negative integer.
were called
\var
{
n
}
times, but do so quickly.
\var
{
n
}
is a
This is most useful in multi-threaded programs, in conjuction with
non-negative integer. This is most useful in multi-threaded
multiple instances of the
\var
{
Random
}
class:
\method
{
setstate()
}
or
programs, in conjuction with multiple instances of the
\var
{
Random
}
\method
{
seed()
}
can be used to force all instances into the sam
e
class:
\method
{
setstate()
}
or
\method
{
seed()
}
can be used to forc
e
internal state, and then
\method
{
jumpahead()
}
can be used to force the
all instances into the same internal state, and then
instances' states as far apart as you like (up to the period of the
\method
{
jumpahead()
}
can be used to force the instances' states as
generator).
far apart as you like (up to the period of the
generator).
\versionadded
{
2.1
}
\versionadded
{
2.1
}
\end{funcdesc}
\end{funcdesc}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment