Random Number Generator

Random Number Generator

Random Number Generator

Random Number Generator


?
Understanding Random Number Generators (RNG)

Understanding Random Number Generators (RNG)

What is a Random Number Generator?

A Random Number Generator (RNG) is a system that produces numbers in an unpredictable way. It is widely used in gaming, cryptography, simulations, and statistical sampling.

Types of RNG

  • Pseudo-Random Number Generator (PRNG): Uses mathematical formulas or algorithms to generate a sequence of numbers that appear random.
  • True Random Number Generator (TRNG): Uses physical processes like electronic noise or radioactive decay to generate numbers that are truly random.

How Does RNG Work in JavaScript?

JavaScript provides a built-in function Math.random() that generates a random decimal number between 0 and 1. To get a number in a specific range, we can use:

    
    function getRandomNumber(min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }
    
    

Example: Try It Yourself

Enter a minimum and maximum value below, then click “Generate” to get a random number.

?
random number generator