From 78d536140f03281815dec859bf6a62a0ec391a38 Mon Sep 17 00:00:00 2001 From: Landon Curt Noll Date: Sun, 10 Sep 2023 15:10:40 -0700 Subject: [PATCH] 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. --- CHANGES | 6 ++++++ cal/README | 4 ++-- cal/randbitrun.cal | 4 ++-- cal/regress.cal | 10 ++++++++-- custom/c_sysinfo.c | 6 +++--- func.c | 16 ++++++++-------- 6 files changed, 29 insertions(+), 17 deletions(-) diff --git a/CHANGES b/CHANGES index 4bb1751..77d13f8 100644 --- a/CHANGES +++ b/CHANGES @@ -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 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: diff --git a/cal/README b/cal/README index d414366..d7db5e3 100644 --- a/cal/README +++ b/cal/README @@ -1130,7 +1130,7 @@ randbitrun.cal the number and length of identical bits runs match what is expected. 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 @@ -1177,7 +1177,7 @@ randrun.cal 64 bit 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. repeat.cal diff --git a/cal/randbitrun.cal b/cal/randbitrun.cal index aa9b837..1c00e26 100644 --- a/cal/randbitrun.cal +++ b/cal/randbitrun.cal @@ -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 * the terms of the version 2.1 of the GNU Lesser General Public License diff --git a/cal/regress.cal b/cal/regress.cal index 0115fd4..b5acde5 100644 --- a/cal/regress.cal +++ b/cal/regress.cal @@ -1737,7 +1737,7 @@ print '024: parsed test_list()'; /* * 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() { @@ -3547,6 +3547,12 @@ define test_trig() vrfy(tnum++ == 3407, '3407: tnum == 3407'); 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 */ vrfy(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; return test_rand(); diff --git a/custom/c_sysinfo.c b/custom/c_sysinfo.c index 8c00dc5..6b12682 100644 --- a/custom/c_sysinfo.c +++ b/custom/c_sysinfo.c @@ -148,9 +148,9 @@ STATIC struct infoname sys_info[] = { (FULL)0}, {"HIST_SIZE", "Default history size", NULL, (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}, - {"INIT_K", "initial 2nd walking a55 table index", NULL, + {"INIT_K", "initial 2nd walking subtractive 100 shuffle table index", NULL, (FULL)INIT_K}, {"INODE_BITS", "inode number size in bits", NULL, (FULL)INODE_BITS}, @@ -222,7 +222,7 @@ STATIC struct infoname sys_info[] = { (FULL)SBYTES}, {"SCNT", "length of subtractive 100 table in FULLs", NULL, (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}, {"SHALFS", "size of additive or shuffle entry in HALFs", NULL, (FULL)SHALFS}, diff --git a/func.c b/func.c index ac8ba8f..9c7e5e5 100644 --- a/func.c +++ b/func.c @@ -997,7 +997,7 @@ f_rand(int count, NUMBER **vals) /* parse args */ switch (count) { case 0: /* rand() == rand(2^64) */ - /* generate an a55 random number */ + /* generate an subtractive 100 shuffle pseudo-random number */ ans = qalloc(); zrand(SBITS, &ans->num); break; @@ -1031,7 +1031,7 @@ f_rand(int count, NUMBER **vals) return NULL; } - /* return the a55 random number */ + /* return the subtractive 100 shuffle pseudo-random number */ 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(); 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; } @@ -1096,14 +1096,14 @@ f_srand(int count, VALUE **vals) /* parse args */ switch (count) { case 0: - /* get the current a55 state */ + /* get the current subtractive 100 shuffle pseudo-random number generator state */ result.v_rand = zsrand(NULL, NULL); break; case 1: switch (vals[0]->v_type) { 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)) { math_error( "srand number seed must be an integer"); @@ -1113,7 +1113,7 @@ f_srand(int count, VALUE **vals) break; 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); break; @@ -1267,7 +1267,7 @@ f_srandom(int count, VALUE **vals) break; 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); break;