[comp.sys.apple2] Random number generation with Hyper C

daye@jacobs.cs.orst.edu (Garion) (01/28/91)

How can I generate random number with Hyper C?  I know there is the frand()
function defined in fp.h, but I don't know how to use it and it adds about
12K to my program, which I really can't do.

Please, I don't know assembly at all, and if it is involved, I would prefer
source code or something.

Thank you.....
--
|  Internet-----           | 'I'll have to teach you a few of my spells.  I    |
|  daye@jacobs.cs.orst.edu |  have one..a fireball..let's see, how did that    |
|  daye@nyssa.cs.orst.edu  |  go..?' - If you don't know, you don't need to    |
         My opinions are my own.  I have opinions, therefore I am....

ericmcg@pnet91.cts.com (Eric Mcgillicuddy) (02/09/91)

Try this:

INT rando()
{
        LOCAL INT seed = 1;
        
        seed = seed * 65533 + 32767;
        return (seed);
}

I got this from the HyperC people circa 1985 in response to the identical
query that you are making now. It is called "mixed congruential method" or so
they say. It returns a signed integer as the result. It will apparently
generate every number once before repeating any. I have not tried it myself,
but feel free. Personally, I don't see how it could work, unless it exploits a
bug in the compiler.

UUCP: bkj386!pnet91!ericmcg
INET: ericmcg@pnet91.cts.com