This question already has an answer here:
I want to generate a number with 75 characters using PHP.
I have searched everywhere and got nothing, except for this: http://dailycoding.com/tools/RandomNumber.aspx
I do not think it is effective to grab it from that page.
What I have tried is this:
rand(1,9999999999999999999999999999999999999);
</div>
try this
function bigNumber() {
# prevent the first number from being 0
$output = rand(1,9);
for($i=0; $i<74; $i++) {
$output .= rand(0,9);
}
return $output;
}
Here you go ...
function genRandomString($length = 75) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$string = '';
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}
return $string;
}
PHP's rand() function may have as little as 15 bits on some platforms, so it's only good for 4 digits at a time. But since to don't actually need the numeric value of the total, call rand(0,9999) to get a 4-digit value, convert it to a string (you'll have concatenate "000" in front of it and then trim to 4 characters with substr() to get leading zeros), and add 4 characters at a time to a big string.
function genRandomNumber($length = 15, $formatted = true) {
$nums = '0123456789';
// First number shouldn't be zero
$out = $nums[mt_rand( 1, strlen($nums)-1 )];
// Add random numbers to your string
for ($p = 0; $p < $length-1; $p++)
$out .= $nums[mt_rand( 0, strlen($nums)-1 )];
// Format the output with commas if needed, otherwise plain output
if ($formatted)
return number_format($out);
return $out;
}
echo genRandomNumber(); // 7,825,104,236
echo genRandomNumber(14,false); // 11648596961188
echo genRandomNumber(25); // 7,154,062,783,835,742,231,986,176
See here: http://codepad.org/yDvyo6MY
It's not possible because, the biggest integer can be generated with a PHP 64 bits is 9223372036854775807. The biggest with a PHP 32 bits is 2147483647.
You can see most information on the PHP documentation.
If you want an equivalent, you can generate a string but you can't manipulate your integer.