Forum Moderators: coopster
Currently they are entered into the DB and assigned a job number that is just an auto-incremented ID. I have labels printed with these auto incrememented numbers to put on the jobs as they come in (service company).
I am trying to figure out if there is some kind of constant math formula that I can use on the auto-incremented ID so the number will not repeat itself again, but at the same time not be random so I can pre print labels with the numbers on them.
I have thought of:
1 - Take the square root of the number - but them what happens if I get a perfect square
2 - Use the sin cos or tangent of the number - I think these will repeat eventually though
3 - take a hash vaule and remove the alpha characters - not sure if this will repeat or not
If anyone has any other ideas, let me know?
Thanks
<?php
$x = 4194;
for ($x = 4194; $x <= 4500; $x += 1) {
$jobnumber = floor(log($x) * 1000000000);
$jobnumber2 = substr("$jobnumber", 4);
echo("$x - $jobnumber2<br />");
}
?>
id (int 11,auto-increment, etc. etc.)
foo (int 11,indexed)
Then, knock up a PHP script to execute the following query 1 Million (or however many you want) times:
INSERT INTO map (foo) VALUES (RAND())
Then, to get your unique ID's that are not sequential but guaranteed never to repeat again; simply use the "id" from this map table selected using the following query:
SELECT id FROM map ORDER BY foo,id LIMIT $x,1
Where $x is the auto-increment ID from your other table.
00 = 4848
01 = 4948
02 = 5048
12 = 5049
13 = 5149
14 = 5249
130 = 485149
131 = 495149
132 = 505149
they're easy to dissemble and translate back into the original numbers.
Or try this.
take your number and divide it by 7.
6 out of 7 integers will produce a 6-digit repeating fraction. chop off the repeating fraction. take the number of decimals you chopped at and make this your first digit.
my number is 411.
/7 = 58.714285714285714285714285...
chop = 58.714285
remove decimal = 58714285
Then to get your number back, divide by 1000000 to get the decimal back. multiply by 7 and round it back to the integer. Because you were accurate to 6 decimals, the product will be off by 0.00001 or less.
For numbers that are evenly divisble by 7 (like 413), your dividend will be a low integer (like 59). to obfuscate this, use the ascii value method described above.
Make it as complicated as possible, and you'll be guaranteed job security for as long as it's in use :-)
bascially it's like getting a deck of n cards, shuffling them, and noting the position of each card for future reference. number 1342 is always at 75422. number 882 is always at 402. and so on.
put it all in a database, and hope to heck you never lose it.