Page 1 of 1
randomly generated number
Posted: Fri Aug 25, 2006 11:49 am
by ibanez270dx
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
Posted: Fri Aug 25, 2006 12:18 pm
by feyd
some use of
rand(),
mt_rand() and such.
Posted: Fri Aug 25, 2006 12:29 pm
by Ollie Saunders
mt_rand() is supposed to be better for some reason that escapes me now.
Re: randomly generated number
Posted: Fri Aug 25, 2006 12:42 pm
by onion2k
ibanez270dx wrote:Is there a way to create a randomly generated 11 digit number? I'd like to use it to create SKU numbers...
SKU numbers shouldn't be random. As a rule, when I generate SKUs I always use a human recognisable format .. for example:
CN-0776-00023
CN - Site
0776 - Category
00023 - Product id
If you need a random bit to obscure the number to the user, tag a few random digits on the end or something. I wouldn't make it all random.
Posted: Fri Aug 25, 2006 1:09 pm
by jabbaonthedais
Why random and not sequential? Basically what onion2k said, but if you don't already have product id's just start with any number and count up (storing each id as a reference in a database).
Posted: Fri Aug 25, 2006 1:40 pm
by ibanez270dx
yes, I like onion2k's idea best... I will probably use sequencial. Thanks everybody!
Posted: Fri Aug 25, 2006 2:23 pm
by nickman013
using rand isnt always reliable too. i used it, but now i had problems because "randomly" the number came out two times and replaced a page with another one.
Posted: Fri Aug 25, 2006 2:37 pm
by Ollie Saunders
Moral of the story is random is no subsitute for sequence when you need to generate a unique number.