Divide the problem into two:
- Create a true random generator or get one. There are better and worse pseudo-random generators. Most algorithmic ones are pseudo. One attempt to a true one would be to place the computer's microphone near the fan or any other noisy equipment and read the least significant bit from the mic port and put together a n-bit number.
- Create the 6 digit numbers.
If you want all 6 digits to be unique, put all digits from 0 to 9 in an array, shuffle it using your random generator and pick the 6 first digits. If first digit can't be zero and the first item in the shuffled array is zero, just pick the 6 next digits.
- If you want each new 6-digit-number to be unique, create an array with the numbers 100,000 to 999,999 and shuffle it. Then pick them in order.