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)?
(In reply to
C++ solution by friedlinguini)
Hmmm... Fried, I used to know some C++ way back when, but reading this took some effort. Looks like you're relying on some standard library functions here, (not sure what random_shuffle() does), which would probably be missing the point of the excercise.
This isn't a straight programming category after all.
|
Posted by levik
on 2003-05-03 13:45:29 |