How can I generate a random string, 20 characters long, A-Z (no lower case), 0-9 only?
I searched online but most scripts to do this are huge (50+ lines). Is there something simpler (maybe 1 line)?
How can I generate a random string, 20 characters long, A-Z (no lower case), 0-9 only?
I searched online but most scripts to do this are huge (50+ lines). Is there something simpler (maybe 1 line)?
Will this suffice ?
<?php
echo strtoupper(substr(sha1(uniqid()),0,20));
OUTPUT :
A71463EA326B72981D21
You could create a string with all the character you want that could be in the random string
$chars = 'ABCDEFG...0123456789';
and then create a for loop that picks a random letter or number in the chars string for 20 timer
$randstring = '';
$string_length;
for ($a = 0; $a < $string_length; $a++) {
$randstring .= $chars[rand(0, strlen($chars) - 1)];
}
Hope it helped!