RND

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Core Language > BuiltIn Functions > Numeric functions >

RND

 

Description

 

Return a random number.

 

Syntax

 

There are 3 possible syntax:

n = RND

n = RND(a, b)

n = RND(numeric_expression)

 

Returns

 

Number

 

Parameters

 

Name

Type

Optional

Meaning

a

Number

No

Any numeric expression

b

Number

No

Any numeric expression

numeric_expression

Number

No

Any numeric expression

 

Remarks

 

RND function has 3 different calling syntax.

 

Extended numeric syntax:

RND executed without any parameters returns a random Extended-precision floating point value that is less than 1, but greater than or equal to 0.

Numbers generated by RND aren't really random, but are the result of applying a pseudo-random transformation algorithm to a starting ("seed") value.

Given the same seed, RND algorithm always produces the same sequence of "random" numbers.

 

Integer class numeric syntax:

RND(a, b) returns a Long-integer in the range of a to b inclusive.  a and b can each be a numeric literal or a numeric expression that evaluates within the full range of a Long-integer (-2,147,483,648 to 2,147,483,647). a can be higher or lower than b.

 

Special mode syntax:

When used with a single numeric expression argument, the value returned by RND depends on the numeric value you supply as the argument, as follows:

with a positive argument, RND generates the next number in sequence based on the initial seed value;

with an argument of 0, RND repeats the last number generated;

a negative argument causes the random number generator to be re-seeded, so subsequent uses of RND with no argument or with a positive argument result in a new sequence of values.

 

Restrictions

 

See also

 

Numeric functions, RNDF,

 

Examples