Announcement

Collapse
No announcement yet.

Constants for Random Numbers Generator

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • John Gleason
    replied
    Here are the Knuth constants for a generator that fits into a quad. It has a period of ~ 2^63, however each random number is only the low 31 bits. Were you thinking something like this?

    Code:
    #COMPILE EXE
    #DIM ALL
    
    FUNCTION PBMAIN () AS LONG
    'Code corrected and reposted below (#5).
    END FUNCTION
    Last edited by John Gleason; 7 Apr 2008, 01:52 PM.

    Leave a comment:


  • Aldo Vitagliano
    started a topic Constants for Random Numbers Generator

    Constants for Random Numbers Generator

    Hi all,

    The RND function incorporated in PB (as in most other languages) is based on the linear congruence algorithm and natively produces a cyclic sequence of 2^31 Long Integers (then reduced to floats in the interval 0-1).
    The formula for successive random numbers is (similar to) the following:
    X(n+1) = k*X(n) MOD m
    where a "good choice" of the constants k and m is crucial for getting a decent "pseudorandomness".
    In the "32 bits" (LONG integer) based generator, m is usually (2^31-1).

    Now I would like to build my own generator producing a much longer cyclic sequence, based on QUAD integers.
    Che choice for m would then be (2^63-1), but I need a "good" and tested value for k.

    Does anybody have the right suggestion ?

    P.S. Knuth gives the value for m = (2^64-1), but I need m = (2^63-1) so that I can use the signed QUAD datatype.

    P.P.S.
    Sorry, I realize that for using standard QUAD arithmetics m can never be (2^63-1). It must be such that m*k < (2^63-1).
    Last edited by Aldo Vitagliano; 7 Apr 2008, 07:54 AM.
Working...
X