Procedural Randomness

version 2 by Aaron Reed

  • Home page
  • Beginning
  • Previous
  • Next



  • Section - I6 routines

    Include (-
    [ setProcSeed item;
        (+ procedural seed +) = ~ ( item * 27923 ) ;
    ];

    [ varySeed x;
        x = (+ procedural seed +);
        x = x * 21739;
        x = ~ x;
        if (x < 0) x = x * -1;
        (+ procedural seed +) = x;
    ];

    [ normalizedSeed sd;
    sd = sd * 16747;
        sd = ~ sd;
        if (sd < 0) sd = sd * -1;
        return sd;
    ];

    [ pRandomNumber n m s seed choice;
        if (n==m) return n;
        if (n>m) { s = n; n = m; m = s; }
        seed = normalizedSeed((+ procedural seed +));
        choice = ( seed % (m-n+1) ) + n;
        varySeed();
        return choice;
    ];
    -).