in reply to Re: random number with range
in thread random number with range
Yes, that works. And that method is great if you want to grab multiple random numbers such that you never get the same one twice. For example, implementing a shuffled deck of cards, or drawing names out of a hat. But if all the OP wants is a single random number, or lots of random numbers uninhibited by such rules as "the number can never repeat", that solution is probably not the best way to do it.
With a shuffled list you have the following problems:
On the other hand, simply picking a random number using rand insures that each subsequent random number isn't dependent on the previously selected numbers, no lists are built and maintained, and thus, time and memory requirements are only O(1).
Dave
|
---|