1function generateRandomString($length = 25) {
2 $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
3 $charactersLength = strlen($characters);
4 $randomString = '';
5 for ($i = 0; $i < $length; $i++) {
6 $randomString .= $characters[rand(0, $charactersLength - 1)];
7 }
8 return $randomString;
9}
10//usage
11$myRandomString = generateRandomString(5);
1//generates 13 character random unique alphanumeric id
2echo uniqid();
3//output - 5e6d873a4f597
1function rand_str() {
2 $characters = '0123456789-=+{}[]:;@#~.?/>,<|\!"£$%^&*()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
3 $randomstr = '';
4 for ($i = 0; $i < random_int(50, 100); $i++) {
5 $randomstr .= $characters[rand(0, strlen($characters) - 1)];
6 }
7 return $randomstr;
8 }
1<?php
2 function RandomString()
3 {
4 $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
5 $randstring = '';
6 for ($i = 0; $i < 10; $i++) {
7 $randstring = $characters[rand(0, strlen($characters))];
8 }
9 return $randstring;
10 }
11
12 RandomString();
13 echo $randstring;
1phpCopy<?php
2$Random_str = uniqid();
3echo "Random String:", $Random_str, "\n";
4?>
5