JavaScript Math.random()

math-random

The Math.random() method returns a random number from 0 (inclusive) up to but not including 1 (exclusive).


Math.random () : generates 0 to 1 random numbers

    <script>
            var a = Math.random();
            document.write(a);
    </script>



Math.random () *10 : generates 0 to 10 random numbers
        <script>
            var a = Math.random()*10;
            document.write(a);
    </script>

Math.random() used with Math.floor() can be used to return random integers

    <script>
            var a = Math.floor (Math.random() * 10) + 1;
            document.write(a);
    </script>