mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
Release calc version 2.11.5t3
This commit is contained in:
@@ -510,7 +510,9 @@ Detailed config descriptions
|
||||
|
||||
5 Report on changes to the run state of calc.
|
||||
|
||||
Bits >= 6 are reserved for future use and should not be used at this time.
|
||||
6 Report on rand() subtractive 100 shuffle generator issues.
|
||||
|
||||
Bits >= 7 are reserved for future use and should not be used at this time.
|
||||
|
||||
By default, "calc_debug" is 0. The initial value may be overridden
|
||||
by the -D command line option.
|
||||
@@ -709,8 +711,8 @@ Detailed config descriptions
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.4 $
|
||||
## @(#) $Id: config,v 29.4 2001/04/08 09:08:27 chongo Exp $
|
||||
## @(#) $Revision: 29.5 $
|
||||
## @(#) $Id: config,v 29.5 2001/04/14 22:46:33 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/config,v $
|
||||
##
|
||||
## Under source code control: 1991/07/21 04:37:17
|
||||
|
82
help/rand
82
help/rand
@@ -1,5 +1,5 @@
|
||||
NAME
|
||||
rand - additive 55 shuffle pseudo-random number generator
|
||||
rand - subtractive 100 shuffle pseudo-random number generator
|
||||
|
||||
SYNOPSIS
|
||||
rand([[min, ] max])
|
||||
@@ -11,7 +11,7 @@ TYPES
|
||||
return integer
|
||||
|
||||
DESCRIPTION
|
||||
Generate a pseudo-random number using an additive 55 shuffle generator.
|
||||
Generate a pseudo-random number using an subtractive 100 shuffle generator.
|
||||
We return a pseudo-random number over the half closed interval [min,max).
|
||||
By default, min is 0 and max is 2^64.
|
||||
|
||||
@@ -38,36 +38,40 @@ DESCRIPTION
|
||||
|
||||
when seeded with the same seed.
|
||||
|
||||
The rand generator has two distinct parts, the additive 55 method
|
||||
and the shuffle method. The additive 55 method is described in:
|
||||
The rand generator has two distinct parts, the subtractive 100 method
|
||||
and the shuffle method. The subtractive 100 method is described in:
|
||||
|
||||
"The Art of Computer Programming - Seminumerical Algorithms"
|
||||
by Knuth, Vol 2, 2nd edition (1981), Section 3.2.2, page 27,
|
||||
Algorithm A.
|
||||
"The Art of Computer Programming - Seminumerical Algorithms",
|
||||
Vol 2, 3rd edition (1998), Section 3.6, page 186, formula (2).
|
||||
|
||||
The period and other properties of the additive 55 method
|
||||
The "use only the first 100 our of every 1009" is described in
|
||||
Knuth's "The Art of Computer Programming - Seminumerical Algorithms",
|
||||
Vol 2, 3rd edition (1998), Section 3.6, page 188".
|
||||
|
||||
The period and other properties of the subtractive 100 method
|
||||
make it very useful to 'seed' other generators.
|
||||
|
||||
The shuffle method is feed values by the additive 55 method.
|
||||
The shuffle method is feed values by the subtractive 100 method.
|
||||
The shuffle method is described in:
|
||||
|
||||
"The Art of Computer Programming - Seminumerical Algorithms"
|
||||
by Knuth, Vol 2, 2nd edition (1981), Section 3.2.2, page 32,
|
||||
Algorithm B.
|
||||
"The Art of Computer Programming - Seminumerical Algorithms",
|
||||
Vol 2, 3rd edition (1998), Section 3.2.2, page 34, Algorithm B.
|
||||
|
||||
The rand generator has a good period, and is fast. It is reasonable as
|
||||
generators go, though there are better ones available. The shuffle
|
||||
method has a very good period, and is fast. It is fairly good as
|
||||
generators go, particularly when it is feed reasonably random
|
||||
numbers. Because of this, we use feed values from the additive 55
|
||||
numbers. Because of this, we use feed values from the subtractive 100
|
||||
method into the shuffle method.
|
||||
|
||||
The rand generator uses two internal tables:
|
||||
|
||||
additive table - 55 entries of 64 bits used by the additive 55 method
|
||||
additive table - 100 entries of 64 bits used by the subtractive
|
||||
100 method
|
||||
|
||||
shuffle table - 256 entries of 64 bits used by the shuffle method
|
||||
feed by the additive 55 method from the additive table
|
||||
feed by the subtractive 100 method from the
|
||||
subtractive table
|
||||
|
||||
The goals of this generator are:
|
||||
|
||||
@@ -95,21 +99,21 @@ DESCRIPTION
|
||||
a standard against which other generators may be measured.
|
||||
|
||||
The Rand book of numbers was groups into groups of 20 digits. The
|
||||
first 55 groups < 2^64 were used to initialize the default additive
|
||||
first 100 groups < 2^64 were used to initialize the default additive
|
||||
table. The size of 20 digits was used because 2^64 is 20 digits
|
||||
long. The restriction of < 2^64 was used to prevent modulus biasing.
|
||||
|
||||
The shuffle table size is longer than the 100 entries recommended
|
||||
by Knuth. We use a power of 2 shuffle table length so that the
|
||||
shuffle process can select a table entry from a new additive 55
|
||||
shuffle process can select a table entry from a new subtractive 100
|
||||
value by extracting its low order bits. The value 256 is convenient
|
||||
in that it is the size of a byte which allows for easy extraction.
|
||||
|
||||
We use the upper byte of the additive 55 value to select the
|
||||
We use the upper byte of the subtractive 100 value to select the
|
||||
shuffle table entry because it allows all of 64 bits to play a part
|
||||
in the entry selection. If we were to select a lower 8 bits in the
|
||||
64 bit value, carries that propagate above our 8 bits would not
|
||||
impact the additive 55 generator output.
|
||||
impact the subtractive 100 generator output.
|
||||
|
||||
It is 'nice' when a seed of "n" produces a 'significantly different'
|
||||
sequence than a seed of "n+1". Generators, by convention, assign
|
||||
@@ -161,7 +165,7 @@ DESCRIPTION
|
||||
The values 'a' and 'c for randreseed64 are taken from the Rand book
|
||||
of numbers. Because m=2^64 is 20 decimal digits long, we will
|
||||
search the Rand book of numbers 20 at a time. We will skip any of
|
||||
the 55 values that were used to initialize the additive 55
|
||||
the 100 values that were used to initialize the subtractive 100
|
||||
generators. The values obtained from the Rand book are:
|
||||
|
||||
a = 6316878969928993981
|
||||
@@ -190,36 +194,40 @@ DESCRIPTION
|
||||
|
||||
The truly paranoid might suggest that my claims in the MAGIC NUMBERS
|
||||
section are a lie intended to entrap people. Well they are not, but
|
||||
you need not take my (Landon Curt Noll) word for it.
|
||||
if you that paranoid why would you use a non-cryprographically strong
|
||||
pseudo-random number generator in the first place? You would be
|
||||
better off using the random() builtin function.
|
||||
|
||||
The random numbers from the Rand book of random numbers can be
|
||||
The two constants that were picked from the Rand Book of Random Numbers
|
||||
The random numbers from the Rand Book of Random Numbers can be
|
||||
verified by anyone who obtains the book. As these numbers were
|
||||
created before I (Landon Curt Noll) was born (you can look up my
|
||||
birth record if you want), I claim to have no possible influence on
|
||||
their generation.
|
||||
created before I (Landon Curt Noll) was born (you can look up
|
||||
my birth record if you want), I claim to have no possible influence
|
||||
on their generation.
|
||||
|
||||
There is a very slight chance that the electronic copy of the
|
||||
Rand book that I was given access to differs from the printed text.
|
||||
I am willing to provide access to this electronic copy should
|
||||
anyone wants to compare it to the printed text.
|
||||
Rand Book of Random Numbers that I was given access to differs
|
||||
from the printed text. I am willing to provide access to this
|
||||
electronic copy should anyone wants to compare it to the printed text.
|
||||
|
||||
When using the a55 generator, one may select your own 55 additive
|
||||
When using the s100 generator, one may select your own 100 subtractive
|
||||
values by calling:
|
||||
|
||||
srand(mat55)
|
||||
srand(mat100)
|
||||
|
||||
and avoid using my magic numbers. Of course, you must pick good
|
||||
additive 55 values yourself!
|
||||
and avoid using my magic numbers. The randreseed64 process is NOT
|
||||
applied to the matrix values. Of course, you must pick good subtractive
|
||||
100 values yourself!
|
||||
|
||||
EXAMPLE
|
||||
> print srand(0), rand(), rand(), rand()
|
||||
RAND state 14384206130809570460 10173010522823332484 5713611208311484212
|
||||
RAND state 2298441576805697181 3498508396312845423 5031615567549397476
|
||||
|
||||
> print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123)
|
||||
17 104 74 47 48 46
|
||||
106 59 99 99 25 88
|
||||
|
||||
> print rand(2,12), rand(2^50,3^50), rand(0,2), rand(-400000, 120000)
|
||||
11 170570393286648531699560 1 -96605
|
||||
2 658186291252503497642116 1 -324097
|
||||
|
||||
LIMITS
|
||||
min < max
|
||||
@@ -248,8 +256,8 @@ SEE ALSO
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.2 $
|
||||
## @(#) $Id: rand,v 29.2 2000/06/07 14:02:33 chongo Exp $
|
||||
## @(#) $Revision: 29.3 $
|
||||
## @(#) $Id: rand,v 29.3 2001/04/14 22:46:33 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/rand,v $
|
||||
##
|
||||
## Under source code control: 1996/01/01 02:16:09
|
||||
|
74
help/srand
74
help/srand
@@ -1,5 +1,5 @@
|
||||
NAME
|
||||
srand - seed the additive 55 shuffle pseudo-random number generator
|
||||
srand - seed the subtractive 100 shuffle pseudo-random number generator
|
||||
|
||||
SYNOPSIS
|
||||
srand([seed])
|
||||
@@ -10,43 +10,43 @@ TYPES
|
||||
return rand state
|
||||
|
||||
DESCRIPTION
|
||||
Seed the pseudo-random number using an additive 55 shuffle generator.
|
||||
Seed the pseudo-random number using an subtractive 100 shuffle generator.
|
||||
|
||||
For integer seed != 0:
|
||||
|
||||
Any buffered rand generator bits are flushed. The additive table
|
||||
for the rand generator is loaded with the default additive table.
|
||||
Any buffered rand generator bits are flushed. The subtractive table
|
||||
for the rand generator is loaded with the default subtractive table.
|
||||
The low order 64 bits of seed is xor-ed against each table value.
|
||||
The additive table is shuffled according to seed/2^64.
|
||||
The subtractive table is shuffled according to seed/2^64.
|
||||
|
||||
The following calc code produces the same effect on the internal
|
||||
additive table:
|
||||
subtractive table:
|
||||
|
||||
/* reload default additive table xor-ed with low 64 seed bits */
|
||||
/* reload default subtractive table xor-ed with low 64 seed bits */
|
||||
seed_xor = seed & ((1<<64)-1);
|
||||
for (i=0; i < 55; ++i) {
|
||||
additive[i] = xor(default_additive[i], seed_xor);
|
||||
for (i=0; i < 100; ++i) {
|
||||
subtractive[i] = xor(default_subtractive[i], seed_xor);
|
||||
}
|
||||
|
||||
/* shuffle the additive table */
|
||||
/* shuffle the subtractive table */
|
||||
seed >>= 64;
|
||||
for (i=55; seed > 0 && i > 0; --i) {
|
||||
for (i=100; seed > 0 && i > 0; --i) {
|
||||
quomod(seed, i+1, seed, j);
|
||||
swap(additive[i], additive[j]);
|
||||
swap(subtractive[i], subtractive[j]);
|
||||
}
|
||||
|
||||
Seed must be >= 0. All seed values < 0 are reserved for future use.
|
||||
|
||||
The additive table pointers are reset to additive[23] and additive[54].
|
||||
Last the shuffle table is loaded with successive values from the
|
||||
additive 55 generator.
|
||||
The subtractive table pointers are reset to subtractive[36]
|
||||
and subtractive[99]. Last the shuffle table is loaded with
|
||||
successive values from the subtractive 100 generator.
|
||||
|
||||
There is no limit on the size of a seed. On the other hand,
|
||||
extremely large seeds require large tables and long seed times.
|
||||
Using a seed in the range of [2^64, 2^64 * 55!) should be
|
||||
Using a seed in the range of [2^64, 2^64 * 100!) should be
|
||||
sufficient for most purposes. An easy way to stay within this
|
||||
range to to use seeds that are between 21 and 93 digits, or
|
||||
64 to 308 bits long.
|
||||
range to to use seeds that are between 21 and 178 digits, or
|
||||
64 to 588 bits long.
|
||||
|
||||
To help make the generator produced by seed S, significantly
|
||||
different from S+1, seeds are scrambled prior to use. The
|
||||
@@ -68,9 +68,9 @@ DESCRIPTION
|
||||
After this call, the rand generator is restored to its initial
|
||||
state after calc started.
|
||||
|
||||
The additive 55 pointers are reset to additive[23] and additive[54].
|
||||
Last the shuffle table is loaded with successive values from the
|
||||
additive 55 generator.
|
||||
The subtractive 100 pointers are reset to subtractive[36]
|
||||
and subtractive[99]. Last the shuffle table is loaded with
|
||||
successive values from the subtractive 100 generator.
|
||||
|
||||
The call:
|
||||
|
||||
@@ -80,14 +80,14 @@ DESCRIPTION
|
||||
|
||||
For matrix arg:
|
||||
|
||||
Any buffered random bits are flushed. The additive table with the
|
||||
first 55 entries of the matrix mod 2^64.
|
||||
Any buffered random bits are flushed. The subtractive table with the
|
||||
first 100 entries of the matrix mod 2^64.
|
||||
|
||||
The additive 55 pointers are reset to additive[23] and additive[54].
|
||||
Last the shuffle table is loaded with successive values from the
|
||||
additive 55 generator.
|
||||
The subtractive 100 pointers are reset to subtractive[36]
|
||||
and subtractive[99]. Last the shuffle table is loaded with
|
||||
successive values from the subtractive 100 generator.
|
||||
|
||||
This form allows one to load the internal additive 55 generator
|
||||
This form allows one to load the internal subtractive 100 generator
|
||||
with user supplied values.
|
||||
|
||||
The randreseed64 process is NOT applied to the matrix values.
|
||||
@@ -114,7 +114,7 @@ DESCRIPTION
|
||||
|
||||
For no arg given:
|
||||
|
||||
Return current a55 generator state. This call does not alter
|
||||
Return current s100 generator state. This call does not alter
|
||||
the generator state.
|
||||
|
||||
This call allows one to take a snapshot of the current generator state.
|
||||
@@ -126,25 +126,25 @@ EXAMPLE
|
||||
RAND state
|
||||
> state = srand();
|
||||
> print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123);
|
||||
32 60 67 71 1 77
|
||||
80 95 41 78 100 27
|
||||
> print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123);
|
||||
52 72 110 15 69 58
|
||||
122 109 12 95 80 32
|
||||
> state2 = srand(state);
|
||||
> print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123);
|
||||
32 60 67 71 1 77
|
||||
80 95 41 78 100 27
|
||||
> print rand(123), rand(123), rand(123), rand(123), rand(123), rand(123);
|
||||
52 72 110 15 69 58
|
||||
122 109 12 95 80 32
|
||||
> state3 = srand();
|
||||
> print state3 == state2;
|
||||
1
|
||||
> print rand();
|
||||
641407694185874626
|
||||
10710588361472584495
|
||||
|
||||
LIMITS
|
||||
for matrix arg, the matrix must have at least 55 integers
|
||||
for matrix arg, the matrix must have at least 100 integers
|
||||
|
||||
LINK LIBRARY
|
||||
RAND *zsrand(ZVALUE *pseed, MATRIX *pmat55)
|
||||
RAND *zsrand(ZVALUE *pseed, MATRIX *pmat100)
|
||||
RAND *zsetrand(RAND *state)
|
||||
|
||||
SEE ALSO
|
||||
@@ -166,8 +166,8 @@ SEE ALSO
|
||||
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
||||
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
##
|
||||
## @(#) $Revision: 29.2 $
|
||||
## @(#) $Id: srand,v 29.2 2000/06/07 14:02:33 chongo Exp $
|
||||
## @(#) $Revision: 29.3 $
|
||||
## @(#) $Id: srand,v 29.3 2001/04/14 22:46:33 chongo Exp $
|
||||
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/srand,v $
|
||||
##
|
||||
## Under source code control: 1996/01/01 04:19:07
|
||||
|
Reference in New Issue
Block a user