数学方法一直给我相同的数字[关闭]

Recently i've been trying to do a repetitive random number in JS, but the problem is that always i have to reload the page to get a new random number, even i try to show it multiple times but the problem is that the number is the same until i refresh the page.

<?php

<script type="text/javascript" charset="utf-8">
    function getNumber(){
        var number = Math.random()
        return number;
    }

    document.write(getNumber()); // NUMBER 1
    document.write(getNumber()); // SAME AS NUMBER 1
    document.write(getNumber()); // SAME AS NUMBER 1
    document.write(getNumber()); // SAME AS NUMBER 1
    document.write(getNumber()); // SAME AS NUMBER 1

</script>

?>

I think it might be because you are using document.write. Use console.log instead and take a look at the console.

console.log(getNumber());
console.log(getNumber());

If you want your results in the browser get a reference to an element, or make and append one.

Math.random() returns a number between 0 and 1. Please read the docs for more information.

Rather than using document.write just update the content of your element like this:

function getNumber(){
    var number = Math.random()
    return number;
}

var div = document.getElementById('result');
div.innerHTML = getNumber();