Rnd#
RandomFloat# = Rnd#(Range)
 
Parameters:

    Range = The Range value that the random number is selected within.
Returns:

    RandomFloat# = The random number selcted by the RND#() function
 

      The Rnd# function will return a random number between and zero and the range value selected. This range value and zero are inclusive, so their both possible outputs of the function. Each time you use the Rnd#() function it will return a different result.

      While Rnd# may appear to produce random results to us humans, the results it produces are in fact part of a 'set'. These number in the millions however, so it's unlikely you'll noticed the values repeating, but they do repeat. This is not actually a PlayBASIC issue, it's an issue with how random number generation techniques employed in computers.



FACTS:


      * The value returned by the Rnd# function is inclusive of zero and bellow the range limit.

      * See Randomize to seed the random number generator



EXAMPLES






Example #1: 10 Random Numbers


      Displaying a list of 10 random numbers between 0 and 100 (inclusive)

  
  For lp=1 To 5
   ; display a random number between 0 and 100
     Print Rnd#(100)
  Next
  
; Display the Screen and wait for the user to press a key
  Sync
  WaitKey
  



This example could output something like this. (could as it'll be random set of results each time you run the program)

  
  66.123
  23.23
  77.56
  1.02
  99.66
  



Top






Example #2: Using Randomize to seed RND generator


In this example we're going to display a set of random numbers, but with one key difference to the above. This time by using the RANDOMIZE command to seed the random number geneator, we can be sure that set of randoms generated, will always be the same.

  
; Set the Random Number Generator Seed
  Randomize 546
  
  For lp=1 To 10
   ; display a random number between 0 and 100
     Print Rnd#(100)
  Next
; Display the Screen and wait for the user to press a key
  Sync
  WaitKey
  



This example could output something like this. (could as it'll be random set of results each time you run the program)

  
  4.35709
  5.4022
  36.3246
  4.07717
  83.0596
  2.17658
  58.6935
  72.0097
  30.0485
  35.2596
  


Top






 
Related Info: Randomize | Rnd | RndRange | RndRange# :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com