Difference between revisions of "Random"

From Xojo Documentation

(Sample Code)
 
Line 16: Line 16:
 
{{Method | name=LessThan | params=Range as [[Integer]] | returntype=[[Integer]] | description=LessThan(Range as Integer) as Integer
Returns a random number as an Integer in the range greater than or equal to 0 and less than Range-1 }}
 
{{Method | name=LessThan | params=Range as [[Integer]] | returntype=[[Integer]] | description=LessThan(Range as Integer) as Integer
Returns a random number as an Integer in the range greater than or equal to 0 and less than Range-1 }}
 
{{Method | name=Number | returntype=[[Double]] | description=Number() as Double
Returns a random number as a Double in the range greater than or equal to 0 and less than 1. }}
 
{{Method | name=Number | returntype=[[Double]] | description=Number() as Double
Returns a random number as a Double in the range greater than or equal to 0 and less than 1. }}
{{Method | name=RandomizeSeed | description=Changes the random objects seed value to start a new sequence of pseudo random numbers.}}
+
{{Method | name=RandomizeSeed | description= RandomizeSeed()
Changes the random objects seed value to start a new sequence of pseudo random numbers.}}
 
</dynamicTable>
 
</dynamicTable>
  

Latest revision as of 18:08, 10 March 2021

Class (inherits from Object)

Used to generate random numbers.

Properties
Seed
Methods
Gaussian Number
InRange RandomizeSeed
LessThan

Notes

Use System.Random to create an instance of this class.

The Random class supersedes the Rnd function. It performs the same functions and more.

A custom random number generator is used. For best results, you should only create a single instance of Random per app.

The Random class's seed is used to initialize the pseudo-random number generator's algorithm so that you can always get the same stream of numbers from the same seed. However, this is not an endian-independent operation. If you set the seed on a big-endian machine to the same value that you used on a little-endian machine, you will get two different streams of pseudo-random numbers.

Sample Code

Use System.Random to get an instance of the class:

Var i As Integer = System.Random.InRange(0, 1000)
MessageBox("The random number is: " + i.ToString)

See Also

Rnd, System.Random functions