echo random_bytes($length);
$length : Length of the random string returned as bytes. $str=random_bytes(7);
echo bin2hex($str);
Output ( Refresh this page to to see how the random number changes )
a4809fb4fe6b5f
<?php
$key = bin2hex(random_bytes(16)); // Generates a 32-character API key
echo "Generated API key: $key";
?>
<?php
$password = bin2hex(random_bytes(8)); // Generates a secure 16-character password
echo "Random password: $password";
?>
<?php
$salt = bin2hex(random_bytes(16)); // 16-byte salt for hashing
echo "Generated salt: $salt";
?>
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.