Skip to main content

Random NumbersDirect link to Random Numbers

Generate random numbers using DevAssure's Advanced Code Blocks feature. This is useful for scenarios where you need dynamic numeric data, such as generating random IDs, quantities, or other numerical values during test automation.

Learn more about Advanced Code Blocks

Generate a Random Floating-Point Number Between 0 and 1Direct link to Generate a Random Floating-Point Number Between 0 and 1

const randomFloat = Math.random();

Random Floating-Point Number Between 0 and 1

Generate a Random Floating-Point Number Between 0 and a Given MaximumDirect link to Generate a Random Floating-Point Number Between 0 and a Given Maximum

const randomFloat = Math.random() * max;

Random Floating-Point Number Between 0 and a Given Maximum

Generate a Random Integer Between 0 and a Given MaximumDirect link to Generate a Random Integer Between 0 and a Given Maximum

const randomInt = Math.floor(Math.random() * (max + 1));

Random Integer Between 0 and a Given Maximum

Generate a Random Integer Between Two Values (Inclusive)Direct link to Generate a Random Integer Between Two Values (Inclusive)

min = Math.ceil(min);
max = Math.floor(max);
const randomInt = Math.floor(Math.random() * (max - min + 1)) + min;

Random Integer Between Two Values (Inclusive)

Generate a Random Number in a Specific RangeDirect link to Generate a Random Number in a Specific Range

let number = Math.random() * (max - min) + min;

Random Number in a Specific Range

Complete code for random numbersDirect link to Complete code for random numbers

Complete code for random numbers

Output for the above codeDirect link to Output for the above code

Output