• Re: KISS 64-bit pseudo-random number generator

    From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Wed Sep 25 18:15:31 2024
    From Newsgroup: comp.lang.forth

    On 9/19/24 06:45, Krishna Myneni wrote:
    On 9/19/24 03:57, albert@spenarnc.xs4all.nl wrote:
    In article <vcgok8$gol7$1@dont-email.me>,
    Krishna Myneni  <krishna.myneni@ccreweb.org> wrote:
    <SNIP>
    Moments of speed
      N       <v> (m/s)    <v^2> (m/s)^2    <v^3> (m/s)^3
    10^2     1181.0956     1656472.7       2604709063.
    10^3     1293.3130     1952149.7       3300955817.
    10^4     1259.3279     1862988.3       3108515117.
    10^5     1260.5577     1872157.8       3147664636.
    10^6     1259.4425     1868918.9       3139487337.
    10^7     1259.6136     1869145.0       3139092438.

    I think for a Monte Carlo simulation at least three tests
    must be done with different seeds.

    Good point. For a meaningful comparison of errors between PRNGs at a specific N, the statistical variation of the <v^n> need to be measured
    for different seed values.

    I can add some code to measure this sigma at each N, with 32 seeds
    uniformly spaced between 0 and UMAX.


    I've calculated the statistical variation in the moments for each set of
    N, using 16 different seeds (spaced apart over the interval for UMAX).
    The standard dev. for the 16 <v^i>, computed for N trials is comparable
    to the relative error between the moment and its theoretical value.
    Thus, the relative errors are indeed a meaningful comparison between the
    two prngs tested here, and I think this implies that for N > 10^5 the
    LCG PRNG (RANDOM) gives more accurate answers than the KISS 64 bit PRNG (RAN-KISS), for this problem. The LCG PRNG is faster than the KISS
    64-bit PRNG.

    minforth stated earlier that he would prefer to use diehard tests to
    decide between which of these two PRNGs to use for computing these
    results from random trials. It will be interesting to see if diehard
    tests are consistent with what I find from actually using the PRNGs and comparing the results to the expected results (for large N and ideal PRNG).

    --
    Krishna




    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Krishna Myneni@krishna.myneni@ccreweb.org to comp.lang.forth on Wed Sep 25 20:45:48 2024
    From Newsgroup: comp.lang.forth

    On 9/25/24 18:15, Krishna Myneni wrote:

    I've calculated the statistical variation in the moments for each set of
    N, using 16 different seeds (spaced apart over the interval for UMAX).
    The standard dev. for the 16 <v^i>, computed for N trials is comparable
    to the relative error between the moment and its theoretical value.
    Thus, the relative errors are indeed a meaningful comparison between the
    two prngs tested here, and I think this implies that for N > 10^5 the
    LCG PRNG  (RANDOM) gives more accurate answers than the KISS 64 bit PRNG (RAN-KISS), for this problem. The LCG PRNG is faster than the KISS
    64-bit PRNG. ...

    The revised test tables for 64-bit prngs RANDOM and RAN-KISS, below,
    include the statistical variations of the moments as a result of
    changing the seed for the prng. These variations are presented as the
    scaled standard deviations for a set of 16 moments, each computed with a different seed. The standard deviations, for a given N,

    {s1, s2, s3} = {sd({<v>(x_i)}), sd({<v^2>(x_i)}), sd({<v^3>(x_i)})}

    where x_i, i=1,16 represents the seed for the random number generator, {<v^j>(x_i)} represents the set of 16 computed moments for each power of
    v, j=1,2,3, and the averaging over the v^j is for N trials.

    These computed standard deviations are scaled by the moments in order to compare these variations with the relative error in the moments,

    s_j/<v^j>

    The relative error, |e_j|, is defined by

    |e_j| = |(<v^j> - <v^j>_th)| / <v^j>_th

    where <v^j>_th is the value of the j^th moment, computed from the
    analytic integral, using the M-B probability density function.

    For example, for the prng RANDOM tests, at N=10^7, the magnitude of the relative error in <v^3>, |e3|, is 4.27e-05 for a random draw of 10^7
    speeds from a Maxwell-Boltzmann distribution. If we repeat this same computation 16 times, each time with a different seed, and look at the normalized standard deviation s3/<v^3> (for N=10^7), this is 3.01e-04.

    Comparing both the relative errors and statistical variations due to
    using different seeds, the tables below show that RANDOM gives
    consistently lower relative errors and statistical seed variations than RAN-KISS, for N >= 10^5.

    --KM


    === RANDOM PRNG TESTS ===
    ' random test-prng

    Moments of speed
    N <v> (m/s) <v^2> (m/s)^2 <v^3> (m/s)^3
    10^2 1220.2444 1761665.1 2879481740.
    10^3 1258.2315 1844889.5 3025976380.
    10^4 1250.0696 1837249.9 3055346856.
    10^5 1259.9899 1870367.4 3143506292.
    10^6 1259.3923 1868383.4 3136761299.
    10^7 1259.6343 1869366.9 3140010276.

    Relative Errors Seed Variations
    N |e1| |e2| |e3| s1/<v> s2/<v^2> s3/<v^3>
    10^2 3.13e-02 5.77e-02 8.30e-02 4.70e-02 9.67e-02 1.54e-01
    10^3 1.19e-03 1.32e-02 3.64e-02 1.32e-02 2.44e-02 3.59e-02
    10^4 7.67e-03 1.73e-02 2.70e-02 4.43e-03 8.24e-03 1.22e-02
    10^5 2.08e-04 4.44e-04 1.07e-03 1.11e-03 1.95e-03 2.78e-03
    10^6 2.66e-04 6.18e-04 1.08e-03 2.82e-04 6.78e-04 1.27e-03
    10^7 7.39e-05 9.15e-05 4.27e-05 7.76e-05 1.72e-04 3.01e-04

    === RAN-KISS PRNG TESTS ===
    ' ran-kiss test-prng

    Moments of speed
    N <v> (m/s) <v^2> (m/s)^2 <v^3> (m/s)^3
    10^2 1212.8900 1702106.0 2666594142.
    10^3 1274.7097 1900519.4 3190481667.
    10^4 1259.6892 1866276.3 3123781859.
    10^5 1260.4578 1872500.5 3147907366.
    10^6 1260.2589 1871249.6 3145073404.
    10^7 1259.8296 1869882.9 3140954422.

    Relative Errors Seed Variations
    N |e1| |e2| |e3| s1/<v> s2/<v^2> s3/<v^3>
    10^2 3.72e-02 8.96e-02 1.51e-01 4.07e-02 8.72e-02 1.46e-01
    10^3 1.19e-02 1.66e-02 1.60e-02 1.26e-02 2.54e-02 3.93e-02
    10^4 3.03e-05 1.74e-03 5.21e-03 3.72e-03 6.96e-03 9.85e-03
    10^5 5.80e-04 1.58e-03 2.47e-03 1.26e-03 2.41e-03 3.63e-03
    10^6 4.22e-04 9.16e-04 1.57e-03 4.89e-04 9.75e-04 1.51e-03
    10^7 8.11e-05 1.85e-04 2.58e-04 1.25e-04 2.54e-04 3.99e-04





    --- Synchronet 3.20a-Linux NewsLink 1.114