Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- A nice function to generate a random string, using any character:
- <?php
- function generateRandStr($length){
- $randstr = "";
- for($i=0; $i<$length; $i++){
- $randnum = mt_rand(0,61);
- if($randnum < 10){
- $randstr .= chr($randnum+48);
- }else if($randnum < 36){
- $randstr .= chr($randnum+55);
- }else{
- $randstr .= chr($randnum+61);
- }
- }
- return $randstr;
- }
- ?>
- Simply use:
- generateRandStr(10);
- Sample output: $%29zon(4f
- <?php
- $random_number = intval( "0" . rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) ); // random(ish) 5 digit int
- $random_string = chr(rand(65,90)) . chr(rand(65,90)) . chr(rand(65,90)) . chr(rand(65,90)) . chr(rand(65,90)); // random(ish) 5 character string
- ?>
- I thought this function (random color) might be of use to someone [to create and return a random hex for HTML colors]:
- <?php
- function get_random_color()
- {
- for ($i = 0; $i<6; $i++)
- {
- $c .= dechex(rand(0,15));
- }
- return "#$c";
- }
- ?>
- http://www.sitepoint.com/php-random-number-generator/
- http://php.net/manual/en/function.rand.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement