Quote:
Originally Posted by carpeperdiem
But what will make it a unique number?
|
Actually, computers can't generate a true random number as any deterministic method would necessitate that it is not 'random' by definition. But for most intensive purposes, you can create a 'psuedo random' number.
Someone mentioned Amazon order numbers and I thought I would have a go at recreating their randomness and pattern of 3-7-7 digits.
Code:
<?php
// Range of numbers
// Minimum number
$min = "1000000";
// Maximum number
$max = "9999999";
echo "105-".
mt_rand($min, $max);
echo "-".
mt_rand($min, $max);
?>
That will spit out an Amazon-esque Order ID. Note, I said 'Order ID' which is what Amazon refers to an order as. Most certainly they would have a unique internal ordering system.
As for testing a used number, well this code snippet uses 14 unique numbers. The possibility for creating a duplicate number with this spread is like 22,876,792,454,961:1 and I don't think it would warrant any test to see if the number was previously generated. You have better odds winning multiple powerball lottos...
- Mike