If you're interested, here's an algorithm that someone else posted on
this list awhile back.  My apologies, but I can't remember who to credit
it to.  I analyzed it and it seems tobe pretty good, although I don't
claim to understand the math.  :)

static const S32 J_RAND32_MAX = 2147483647L;
static S32 glCurrentSeed = 0xED0000ED; // a good default, must never be
zero!
static const double cdRandScale = 1.0 / 2147483648.0; // will never hit
1.0

// calculates the next random number and puts the value in glCurrentSeed
//
U32 j_Rand()
        {
        U32 ulLoWord, ulHiWord;

        ulLoWord = 16807 * (glCurrentSeed & 0xffff);
        ulHiWord = 16807 * (U32(glCurrentSeed) >> 16);
        ulLoWord += (ulHiWord & 0x7fff) << 16;

        if (ulLoWord > J_RAND32_MAX)
                {
                ulLoWord &= J_RAND32_MAX;
                ulLoWord++;
                }

        ulLoWord += ulHiWord >> 15;

        if (ulLoWord > J_RAND32_MAX)
                {
                ulLoWord &= J_RAND32_MAX;
                ulLoWord++;
                }

        glCurrentSeed = ulLoWord;

        return (U32) glCurrentSeed;
        }




Robert Cohen wrote:
> 
> I had that problem.
> 
> Rob
> 
> -----Original Message-----
> From:   Aaron Ardiri [SMTP:[EMAIL PROTECTED]]
> Sent:   Thursday, July 20, 2000 9:40 AM
> To:     Palm Developer Forum
> Subject:        Re: Random number
> 
> > How can I generate random numbers?
> 
>   SysRandom()
> 
>   but, maybe you want to generate your own :P SysRandom() works fine
>   for me, but previous investigation by people on the list has proven
>   that it does not generate a good set of random numbers
> 
>   cheers
> 
> az.
> --
> Aaron Ardiri
> Java Certified Programmer      http://www.hig.se/~ardiri/
> University-College i Gavle     mailto:[EMAIL PROTECTED]
> SE 801 76 Gavle SWEDEN
> Tel: +46 26 64 87 38           Fax: +46 26 64 87 88
> Mob: +46 70 656 1143           A/H: +46 8 668 78 72
> 
> if you enjoy it, then it aint work :) - rule #106 of life
> 
> --
> For information on using the Palm Developer Forums, or to unsubscribe, please see 
>http://www.palmos.com/dev/tech/support/forums/
> 
> --
> For information on using the Palm Developer Forums, or to unsubscribe, please see 
>http://www.palmos.com/dev/tech/support/forums/

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to