fix rand pseudo-random number generator

Fixed more documentation and code comments that referred to the old
additive 55 (a55) shuffle pseudo-random number generator.  We have
been using the subtractive 100 shuffle pseudo-random number generator
in place of the additive 55 generator for a while now.
This commit is contained in:
Landon Curt Noll
2023-09-10 15:10:40 -07:00
parent 8caa8d8635
commit 78d536140f
6 changed files with 29 additions and 17 deletions

View File

@@ -170,6 +170,12 @@ The following are the changes from calc version 2.14.3.5 to date:
Added to test 94dd, read of a number of new calc resource files Added to test 94dd, read of a number of new calc resource files
that are not already read as a result of the calc regression test suite. that are not already read as a result of the calc regression test suite.
Fixed more documentation and code comments that referred to the
old additive 55 (a55) shuffle pseudo-random number generator.
We have been using the subtractive 100 shuffle pseudo-random
number generator in place of the additive 55 generator for a
while now.
The following are the changes from calc version 2.14.3.4 to 2.14.3.5: The following are the changes from calc version 2.14.3.4 to 2.14.3.5:

View File

@@ -1130,7 +1130,7 @@ randbitrun.cal
the number and length of identical bits runs match what is expected. the number and length of identical bits runs match what is expected.
By default, run_cnt is to test the next 65536 random values. By default, run_cnt is to test the next 65536 random values.
This tests the a55 generator. This tests the subtractive 100 shuffle pseudo-random number generator.
randmprime.cal randmprime.cal
@@ -1177,7 +1177,7 @@ randrun.cal
64 bit values. By default, run_cnt is to test the next 65536 64 bit values. By default, run_cnt is to test the next 65536
random values. random values.
This tests the a55 generator. This tests the subtractive 100 shuffle pseudo-random number generator.
repeat.cal repeat.cal

View File

@@ -1,7 +1,7 @@
/* /*
* randbitrun - check rand bit run lengths of the a55 generator * randbitrun - check rand bit run lengths of the subtractive 100 shuffle generator
* *
* Copyright (C) 1999 Landon Curt Noll * Copyright (C) 1999,2023 Landon Curt Noll
* *
* Calc is open software; you can redistribute it and/or modify it under * Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License * the terms of the version 2.1 of the GNU Lesser General Public License

View File

@@ -1737,7 +1737,7 @@ print '024: parsed test_list()';
/* /*
* test 025: define test_rand for test 15dd * test 025: define test_rand for test 15dd
* *
* This function tests the a55 shuffle pseudo-random number generator. * This function tests the subtractive 100 shuffle pseudo-random number generator.
*/ */
define test_rand() define test_rand()
{ {
@@ -3547,6 +3547,12 @@ define test_trig()
vrfy(tnum++ == 3407, '3407: tnum == 3407'); vrfy(tnum++ == 3407, '3407: tnum == 3407');
pi = pi(1e-20); pi = pi(1e-20);
/* test trigonometric sine */
vrfy(sin(0, 1e-10) == 0,
strcat(str(tnum++), ': sin(0, 1e-10) == 0'));
vrfy(sin(pi/6, 1e-10) == 0.5,
strcat(str(tnum++), ': sin(pi/6, 1e-10) == 0.5'));
/* test versed trigonometric sine */ /* test versed trigonometric sine */
vrfy(versin(0, 1e-10) == 0, vrfy(versin(0, 1e-10) == 0,
strcat(str(tnum++), ': versin(0, 1e-10) == 0')); strcat(str(tnum++), ': versin(0, 1e-10) == 0'));
@@ -8297,7 +8303,7 @@ return test_list();
/* /*
* test 15dd: test the a55 shuffle pseudo-random number generator * test 15dd: test the subtractive 100 shuffle pseudo-random number generator
*/ */
print; print;
return test_rand(); return test_rand();

View File

@@ -148,9 +148,9 @@ STATIC struct infoname sys_info[] = {
(FULL)0}, (FULL)0},
{"HIST_SIZE", "Default history size", NULL, {"HIST_SIZE", "Default history size", NULL,
(FULL)HIST_SIZE}, (FULL)HIST_SIZE},
{"INIT_J", "initial 1st walking a55 table index", NULL, {"INIT_J", "initial 1st walking subtractive 100 shuffle table index", NULL,
(FULL)INIT_J}, (FULL)INIT_J},
{"INIT_K", "initial 2nd walking a55 table index", NULL, {"INIT_K", "initial 2nd walking subtractive 100 shuffle table index", NULL,
(FULL)INIT_K}, (FULL)INIT_K},
{"INODE_BITS", "inode number size in bits", NULL, {"INODE_BITS", "inode number size in bits", NULL,
(FULL)INODE_BITS}, (FULL)INODE_BITS},
@@ -222,7 +222,7 @@ STATIC struct infoname sys_info[] = {
(FULL)SBYTES}, (FULL)SBYTES},
{"SCNT", "length of subtractive 100 table in FULLs", NULL, {"SCNT", "length of subtractive 100 table in FULLs", NULL,
(FULL)SCNT}, (FULL)SCNT},
{"SEEDXORBITS", "low bits of a55 seed devoted to xor", NULL, {"SEEDXORBITS", "low bits of subtractive 100 shuffle pseudo-random number generator seed devoted to xor", NULL,
(FULL)SEEDXORBITS}, (FULL)SEEDXORBITS},
{"SHALFS", "size of additive or shuffle entry in HALFs", NULL, {"SHALFS", "size of additive or shuffle entry in HALFs", NULL,
(FULL)SHALFS}, (FULL)SHALFS},

16
func.c
View File

@@ -997,7 +997,7 @@ f_rand(int count, NUMBER **vals)
/* parse args */ /* parse args */
switch (count) { switch (count) {
case 0: /* rand() == rand(2^64) */ case 0: /* rand() == rand(2^64) */
/* generate an a55 random number */ /* generate an subtractive 100 shuffle pseudo-random number */
ans = qalloc(); ans = qalloc();
zrand(SBITS, &ans->num); zrand(SBITS, &ans->num);
break; break;
@@ -1031,7 +1031,7 @@ f_rand(int count, NUMBER **vals)
return NULL; return NULL;
} }
/* return the a55 random number */ /* return the subtractive 100 shuffle pseudo-random number */
return ans; return ans;
} }
@@ -1064,7 +1064,7 @@ f_randbit(int count, NUMBER **vals)
} }
/* /*
* generate an a55 random number or skip random bits * generate an subtractive 100 shuffle pseudo-random number or skip random bits
*/ */
ans = qalloc(); ans = qalloc();
cnt = ztolong(vals[0]->num); cnt = ztolong(vals[0]->num);
@@ -1078,7 +1078,7 @@ f_randbit(int count, NUMBER **vals)
} }
/* /*
* return the a55 random number * return the subtractive 100 shuffle pseudo-random number
*/ */
return ans; return ans;
} }
@@ -1096,14 +1096,14 @@ f_srand(int count, VALUE **vals)
/* parse args */ /* parse args */
switch (count) { switch (count) {
case 0: case 0:
/* get the current a55 state */ /* get the current subtractive 100 shuffle pseudo-random number generator state */
result.v_rand = zsrand(NULL, NULL); result.v_rand = zsrand(NULL, NULL);
break; break;
case 1: case 1:
switch (vals[0]->v_type) { switch (vals[0]->v_type) {
case V_NUM: /* srand(seed) */ case V_NUM: /* srand(seed) */
/* seed a55 and return previous state */ /* seed subtractive 100 shuffle pseudo-random number generator and return previous state */
if (!qisint(vals[0]->v_num)) { if (!qisint(vals[0]->v_num)) {
math_error( math_error(
"srand number seed must be an integer"); "srand number seed must be an integer");
@@ -1113,7 +1113,7 @@ f_srand(int count, VALUE **vals)
break; break;
case V_RAND: /* srand(state) */ case V_RAND: /* srand(state) */
/* set a55 state and return previous state */ /* set subtractive 100 shuffle pseudo-random number generator state and return previous state */
result.v_rand = zsetrand(vals[0]->v_rand); result.v_rand = zsetrand(vals[0]->v_rand);
break; break;
@@ -1267,7 +1267,7 @@ f_srandom(int count, VALUE **vals)
break; break;
case V_RANDOM: /* srandom(state) */ case V_RANDOM: /* srandom(state) */
/* set a55 state and return previous state */ /* set subtractive 100 shuffle pseudo-random number generator state and return previous state */
result.v_random = zsetrandom(vals[0]->v_random); result.v_random = zsetrandom(vals[0]->v_random);
break; break;