Jump to content

Archived

This topic is now archived and is closed to further replies.

ibanez270dx

randomly generated number

Recommended Posts

Hi,
Is there a way to create a randomly generated 11 digit number? I'd like to use it to create SKU numbers...

Thanks,
- Jeff

Share this post


Link to post
Share on other sites
here are a couple options:
[code]
<?php
// randomly generate and concatonate 11 digits
$sku = '';
for ($i = 0; $i < 11; $i++) {
  $num = rand(0,9);
  $sku .= $num;
}
echo $sku;


// randomly generate the entire number and pad with leading zeros
echo sprintf("%011d", rand(0,99999999999));
?>
[/code]

hope this helps

Share this post


Link to post
Share on other sites
Hi all,

I couldn't hope to match [b]obsidian's[/b] post, but you could just try this:

[code]
<?php
$num = rand(11111111111,99999999999);
print $num;
?>
[/code]

Hope it helps!
Iceman

Share this post


Link to post
Share on other sites
However, as the max value of an integer is 2,147,483,647 (10 digits) I'd go with Obsidian's first method

Share this post


Link to post
Share on other sites
[quote author=Barand link=topic=105619.msg422611#msg422611 date=1156636418]
However, as the max value of an integer is 2,147,483,647 (10 digits) I'd go with Obsidian's first method
[/quote]'

If the max size of an integer is 10 digits - the max value is 2,147,483,647? Can you tell me how you calculate that? Thanks.

Share this post


Link to post
Share on other sites
The maximum value depends on the system. 32 bit systems have a maximum signed integer range of -2147483648 to 2147483647. [2^31-1]

Source: http://ca.php.net/intval

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.