Re: Random Numbers
Posted in 1995
} } Quoting Jack Parker... } } } } > } } > } } > Anybody know of a random number generator for I4gl? } } > } } > } } } } try this. } } } } # 4gl code } } CALL c_rand() RETURNING rnd # RANDOM BETWEEN 1 AND 32767 } } } } } } /* c code */ } } #include <stdlib.h> } } } } c_rand() } } { } } retint(rand()); } } return(1); } } } } } } Unfortunately you'll get the SAME random numbers everytime you run your } program! I'd recommend using } } srand48(time(0)); } } first to set an entry point for the random number generator and then I'd use } } lrand48(); } } to actually generate the random numbers. Actually rand() will return a different number each time, they WILL follow the same sequence each time (Oh, that's exactly what Dave said). Dave is right - you should have called srand() at some point to seed things. The _rand48 series of instructions give you a better random than just plain old rand(). cheers j. A goldmine of misinformation _____________________________________________________________________________ Jack Parker - Hewlett Packard, BSMC Boise, Idaho, USA jparker@hpbs3645.boi.hp.com _____________________________________________________________________________ "A thing is bigger for being shared" - Gaelic _____________________________________________________________________________ Any opinions expressed herein are my own and not those of my employers. _____________________________________________________________________________