Suppose you want to make a random 9 digit number, using every number from 1 to 9 exactly once. You have a process called random(top) that gives a random number up to top (if top was 5, it would give random numbers from 1 to 5)
a) How could you do this?
b) If top couldn't be more than 9, how could you do this using random(top) only 9 times (or less)?
Start with digits 1-9 in a vector/array/list/string/whatever.
Let d[n] denote the digit in the nth place.
For i from 1 to 8, swap d[i] with d[i + random(10-i) - 1]
Convert digits to an actual number.
In C++ (borrowing a bit from Charlie's solution):
std::string digits("123456789");
for (int i = 1; i <= 9; ++i)
std::swap(digits[i - 1], d[i + random(10-i) - 2]);
return boost::lexical_cast<int>(digits);