Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#2 Random number generator

closed
nobody
None
5
2009-04-06
2009-03-22
smartroad
No

Some form of RND function with the format RND(n) where 'n' is the number between 0 to 'n'. May need a corresponding seeding instruction RNDSEED(n) where 'n' is the seeding number.

Discussion

  • Hugh Considine
    Hugh Considine
    2009-04-06

    • status: open --> closed
     
  • Hugh Considine
    Hugh Considine
    2009-04-06

    This should already be implemented in the latest build, http://gcbasic.sourceforge.net/newfiles/update.zip. I implemented it some time last year, but just haven't updated the documentation yet.

    To get a random number, use the Random function. To seed the generator, use the Randomise sub. Have a look at random.h, you'll find it in the include/lowlevel subdirectory of wherever GCBASIC is installed (typically C:\Program Files\GCBASIC\include\lowlevel\random.h)

    Random will return a value between 0 and 255. Try this code if you need a custom maximum:

    function RND(RandomMax)
    RND = Random % RandomMax
    end function

    This will return a number between 0 and RandomMax - 1.