From: Sidney Cadot (sidney_at_janis.pds.twi.tudelft.nl)
Date: 2000-03-09 22:12:53
Hi, The random generator as available in lib/common/rand.s is quite awkward. It enters a cycle at the 264th call of length 95. 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: signed rand(void) { unsigned STATE=0; STATE = (STATE*5U)+13841U; return (signed)(STATE&0x7FFFU); } but he forgot to do a CLC after adding (4*STATE) and (STATE). The intended behaviour however may be even worse: the values as obtained by that method alternate between even and odd. Flipping a coin using such a rand()%2 would yield nice odds in the casino :-) 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. Regards, Sidney Cadot ---------------------------------------------------------------------- To unsubscribe from the list send mail to majordomo_at_musoftware.de with the string "unsubscribe cc65" in the body(!) of the mail.
This archive was generated by hypermail 2.1.3 : 2001-12-14 22:05:35 CET