Re: [cc65] faulty random generator

Date view Thread view Subject view

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2000-03-09 22:36:34


Hi!

> This is in part due to a bug in the rand() function: the author (Ullrich
> or Steve Judds, I don't know who is to blame ;-)) intended to do this:

The original code already has the error you mention. I have to admit that I
just used the code without doing an analysis of the generated random number
sequences. If I had to do this, using existing code would be worthless, since
I could just as well use one of the generators from the Knuth book and
implement it in 6502 assembly (it would be the same amount of work).

Apart from that, I don't think that this code was written by Steve Judd. Steve
is writing almost perfect code and he is a genius when it comes to math (and,
besides that, he is a very nice guy :-). I'm sure he would not write and post
a routine with such an obvious error.

> I will implement a better (high-period) random function soon. I would like
> it to have a period > 2^16, however this would mean that the state would
> have to be more than one word. In principle, that's no problem: the
> srand() call could clear the high-order state bits.

I would be glad to add your code to the library. But please keep in mind that
for most purposes (programming games or similar) it is better to have a short
routine that produces slightly worse random numbers than a perfect random
number generator that has a large memory footprint. This is the reason why I
did choose the current algorithm instead of the other (larger) one that is
also available from The Fridge.

If you have a really good algorithm that is large, I would suggest to use a
shorter one for the standard rand() C function, and add your code as an
extension. Unix C libraries usually have rand() (ANSI C) and random() (BSD).
The latter is often slower and larger but produces better random number
sequences. We could use a similar approach for cc65.

Regards


	Uz


--
Ullrich von Bassewitz                                  uz_at_musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2001-12-14 22:05:35 CET