ibanez270dx Posted August 25, 2006 Share Posted August 25, 2006 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 Link to comment https://forums.phpfreaks.com/topic/18653-randomly-generated-number/ Share on other sites More sharing options...
obsidian Posted August 25, 2006 Share Posted August 25, 2006 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 zerosecho sprintf("%011d", rand(0,99999999999));?>[/code]hope this helps Link to comment https://forums.phpfreaks.com/topic/18653-randomly-generated-number/#findComment-80398 Share on other sites More sharing options...
Iceman512 Posted August 26, 2006 Share Posted August 26, 2006 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 Link to comment https://forums.phpfreaks.com/topic/18653-randomly-generated-number/#findComment-80667 Share on other sites More sharing options...
Barand Posted August 26, 2006 Share Posted August 26, 2006 However, as the max value of an integer is 2,147,483,647 (10 digits) I'd go with Obsidian's first method Link to comment https://forums.phpfreaks.com/topic/18653-randomly-generated-number/#findComment-80947 Share on other sites More sharing options...
extrovertive Posted August 27, 2006 Share Posted August 27, 2006 [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 https://forums.phpfreaks.com/topic/18653-randomly-generated-number/#findComment-80966 Share on other sites More sharing options...
AndyB Posted August 27, 2006 Share Posted August 27, 2006 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 Link to comment https://forums.phpfreaks.com/topic/18653-randomly-generated-number/#findComment-80973 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.