random - Random Integers

Prev Next

Function Names

random

Description

Generates a random integer number. Biggest range (from lower to upper boundary) is 2^31-1.

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

1, 2

Parameters

No.TypeDescription
1.
input
numeral 1st boundary value

If specified alone, then random numbers returned lie between 0 and specified value.

Opt. 2.
input
numeral 2nd boundary value

If specified, then it will serve as 2nd boundary value. It does not matter if it is smaller or greater than the 1st boundary value.

Return value

TypeDescription
numeral Random number

Randomly generated number

Exceptions

Values provided is not a numerals

Examples

      for (i[]=1, i[]<=10, i[]++) print( random(1000),        " " ); echo;
      for (i[]=1, i[]<=10, i[]++) print( random( 1000,  950), " " ); echo;
      for (i[]=1, i[]<=10, i[]++) print( random(-1000, -950), " " ); echo;
      for (i[]=1, i[]<=10, i[]++) print( random(   -5,    3), " " ); echo;
      for (i[]=1, i[]<=10, i[]++) print( random(   -1,    1), " " ); echo;

Output

791 198 451 106 363 180 716 350 353 966
980 958 985 989 999 994 976 952 988 988
-992 -983 -971 -963 -979 -991 -957 -952 -969 -992
-4 1 -2 2 -4 3 -2 0 0 -1
-1 1 1 -1 1 0 1 -1 0 -1
Try it yourself: Open LIB_Function_random.b4p in B4P_Examples.zip. Decompress before use.