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.
Vectorization: This function supports vectorization. Sets and nested sets containing numeric values are also supported.

Call as: function

Restrictions

Indirect parameter passing is disabled
Vectorization is allowed in the 1st function parameter

Parameter count

1, 2

Parameters

No.TypeDescription
1.
input
numeral
set
1st boundary value

If specified alone, then random numbers returned lie between 0 and specified value. Multiple values can be provided in a set for vectorization.

Opt. 2.
input
numeral
set
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. Multiple values can be provided in a set for vectorization.

Return value

TypeDescription
numeral
set
Random number

Randomly generated number(s)

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;
               echo;
           echo("Vectorization exmaple: ", random({10:1000}) ); // Provide 10 random numbers.

Output

895 368 647 277 557 290 976 176 952 716
957 983 970 965 996 999 990 968 971 970
-961 -965 -997 -977 -992 -984 -965 -983 -957 -978
1 -5 3 1 -2 -3 -2 2 -2 3
-1 0 0 -1 0 -1 -1 -1 1 1

Vectorization exmaple: {895,250,843,744,571,736,37,730,5,98}
Try it yourself: Open LIB_Function_random.b4p in B4P_Examples.zip. Decompress before use.