--- In [email protected], "suchismit mahapatra" <[EMAIL PROTECTED]> wrote:
>
> its great to hear from you josh.
> must say ur approach is interesting.
> but the thing is even ur method doesnt give us the perfect
> random7generator.
<snip>

May I suggest to ask the "ultimate judge" on that matter? Donald
Knuth's The Art Of Computer Programming, volume 3, gives a more than
thorough introduction into pseudo-random number generation. I don't
have the time to look it up by now, but at least I can agree with Josh
that the approach in your original email was flaky. If you get the
chance to get hold of a copy of The Art Of Computer Programming vol.
3, please, do it, and read this chapter. It's a hard read, I know, but
it's definitely worth the time you spend on it.
I don't have the time by now, otherwise I would do it myself. Sorry
for that.

What about the following approach:
1) Invoke r5g(); if the number is 4, go back to step 1 immediately.
2) In case of 0 or 1, set the "Base" to 0, otherwise set the "Base" to 4.
3) Invoke r5g() another time; if the result is 4, go back to step 1
immediately.
4) Add the number from step 3 to the "Base" from step 2.
5) If the result is 7, go back to step 1 immediately.

This of course means that sometimes the generator has to be invoked
more than twice per number, but what the heck, I think this extra time
is not worth hard consideration.
And (from my gut feeling) I think it will have the advantage that all
numbers will occur equally often.

BTW may I dare to ask why you want to use a r5g() to resemble a r7g()?
What's the use of such a trick? It would make much more sense to write
your pseudo-random number generator (PRNG) such that it can be used
for any integer (in its technically defined domain of valid values)
than to use a "narrow" PRNG to implement a "wider" PRNG. What are the
restrictions that bind you to a r5g()?

As always, if someone can prove I'm wrong, please do so! Thomas is not
the only one to enjoy learning new tricks. ;-)

Regards,
Nico

Reply via email to