random Summary Generates a random number. Signatures Click on a signature to select it and view its documentation. public static double random() public static int random(int n) public static int random(int start, int stop) public static double random(double n) public static double random(double start, double stop) Usage public static double random() public static int random(int n) public static int random(int start, int stop) public static double random(double n) public static double random(double start, double stop) Returns A random number greater than or equal to zero (0) and less than one (1). [0...1) A whole number greater than or equal to zero (0) and less than n. [0...n) A whole number greater than or equal to start and less than stop. [start...stop) A random value greater than or equal to zero (0) and less than n. [0...n) A random number greater than or equal to start and less than stop. [start...stop) Parameters n The upper limit for the random number generation (non-inclusive). Parameters start The lower limit for the random number generation (inclusive). stop The upper limit for the random number generation (non-inclusive). Parameters n The upper limit for the random number generation (non-inclusive). Parameters start The lower limit for the random number generation (inclusive). stop The upper limit for the random number generation (non-inclusive). Description Generates a random number greater than or equal to zero (0) and less than one (1). [0...1) Generates a random, whole 32-bit integer number greater than or equal to zero (0) and less than n. [0...n) Generates a random, whole 32-bit integer number greater than or equal to start and less than stop. [start...stop) Generates a random number greater than or equal to zero (0) and less than n. [0...n) Generates a random number greater than or equal to start and less than to stop. [start...stop) Examples Basic Usage 123import System; Console.log(Math.random()); Basic Usage 1234import System; // Generate a random number between 0 and 99 (inclusive)Console.log(Math.random(100)); Basic Usage 1234import System; // Generate a random number between 1 and 100 (inclusive)Console.log(Math.random(1, 101)); Basic Usage 123import System; Console.log(Math.random(2.2d)); Basic Usage 123import System; Console.log(Math.random(1.1d, 2.2d)); Share HTML | BBCode | Direct Link