Generating unique random integers
Quote:
> > There is an algorithm in _Numerical Recipes in C_
> Note that while Numerical Recipes in C is a pretty good
> book on the computational parts. Their examples aren't
> usually very efficient and some even violate the C standard.
That is why, in the part you cut out, I said that it is easy
to wrap their algorithm in a class. Yes they do some stuff
that is not very elegant and looks foreign to a C++ coder.
But it's nothing an old C hacker would be surprised by.
(Might not like the flavour. They do things like a kludge to
get around starting arrays at zero.)
And the important part is the algorithm anyway. (And in
this particular case some "magic numbers" that have been
chosen to have certain special relationships.) It's pretty
rare that I use nummies code from any source without
modifying it pretty heavily. (Nummies libraries are, of
course, a different matter.)
And speaking of efficiency: In a random number generator,
it is unlikely that efficiency will be all that critical. The actual
generation of the random number is unlikely to be a big part
of the total computation involved. What is likely to be most
important is the quality of the number in terms of things like
how long the period is, how well the sequence obeys tests
of statistics, how hard it is to predict the next number given
a sequence, and so on. If the algorithm is good on these
scores, it is unlikely for most applications that absolute top
efficiency will be critical.
But if it is, then a good nummies book will give refs to the
more advanced literature. And Press et al. do this.
And if you are writing an application that needs this sort
of high performance, you likely already have many of
these references and have forgotten more about nummies
than I will ever know.
--
Dan Evens
(Standard disclaimers etc. No spam please.)