如何在表单字段中放置随机生成的数字?

Like this:

form:
title - [ ]
description - [ ]
password - [ ]

Don't want your own password?
[Generate one]

And then the [Generate one] button will just place a random number in the password field or whatever field desired.

How would I do this?

I was thinking that this would do it:

function generate() {
$placerand = rand();
}

and then place it in the 'value' of the form field.

<form>
<input type="text" value="<?php echo $placerand; ?>" placeholder="password">
<input type="submit" onclick="generate()" value="Generate a random number"><>
</form>

but, I'm thinking that the php function is a javascript function, so that wouldn't work... Would it?

Here is an example

<input type="Textbox" id="pwbx" />

<button OnClick="GetRandom()" type="button">generate</button>
<script>
    function GetRandom()
    {
        var myElement = document.getElementById("pwbx")
        myElement.value = Math.random()
    }
</script>

first you can use javascript math.random() , it will output a random number each time it is called. Place it anywhere you want on onclick event

function sampleExplanation(){
 var x = jQuery("#demo");
 x.html(Math.floor((Math.random()*10)+1));

}  

"demo" id of the element where the data will be placed.

this is sample function which will generate random numbers between 1 - 10. In a same way you can write your own function to generate a random number in any range.

one-liner to generate strings:

<?php
substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',5)),0,5);
?>

The strings can be repeated to have the possibility that a character appears multiple times. You can increase the size I have set it to 5

I used you same code and i achieved what you really wanted, this is how i got it done (working):

    <?php
srand ((double) microtime() * 1000000);
$random3 = rand(1000,9999);
?>
<?php echo $random3; ?>
<form>
<input type="text" value="<?php echo $random3; ?>" placeholder="password">
<input type="submit" onclick="generate()" value="Generate a random number">
</form>