Jump to content

randomly generated number


ibanez270dx

Recommended Posts

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
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.