13.07.2015 Views

Turbo Basic

Turbo Basic

Turbo Basic

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

RND functionFunctionSyntaxRemarksSee AlsoExampleRND returns a random number.y = RND[(numerjc express jon)]RND returns a random double-precision value between ° and 1.Numbers generated by RND aren't really random, but are theresult of applying a pseudorandom transformation algorithm to astarting, or seed, value. Given the same seed, <strong>Turbo</strong> <strong>Basic</strong>'s RNDalgorithm .always produces the same chain of "random" numbers.The performance of RND depends on the optional numeric valueyou supply as the argument. With no argument or with a positiveargument, RND generates the next number in sequence based onits initial seed value.With an argument of 0, RND repeats the last number generated.A negative argument causes the random number generator to bereseeded, so that subsequent uses of RND with no argument orwith a positive argument result in a new sequence of values.In general, use RANDOMIZE TIMER once at the start of yourprogram to produce a new sequence of values with the RND statement.Don't use ° or negative value arguments with RND unlessyou are looking for the special effects caused by those values.To produce random integers between 1 and n, inclusive, use thistechnique:randomNo% = INT(RND * n) + 1Better yet, create it as a function:DEF FNRndInt% (x%) = INT(RND * x%) + 1RANDOMIZEFOR I! = 1 TO 10 STEP 1.34PRINT USING "###.##-11 :RND(I!)NEXT I!END<strong>Turbo</strong> <strong>Basic</strong> Reference Directory 329

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!