Path: news.weeg.uiowa.edu!news.uiowa.edu!uunet!cs.utexas.edu!sun-barr!olivea!spool.mu.edu!sol.ctr.columbia.edu!destroyer!news.iastate.edu!iscsvax.uni.edu!fisher2557 From: fisher2557@iscsvax.uni.edu Newsgroups: comp.sys.apple2 Subject: Re: Random Routine Message-ID: <1992Oct20.092337.7858@iscsvax.uni.edu> Date: 20 Oct 92 14:23:37 GMT References: <1992Oct20.032343.27782@cs.uow.edu.au> Organization: University of Northern Iowa Lines: 29 > I am after a simply random routine in 65816 assembler which would > return a 8bit number (though 16bit would be acceptable, but I really only > need 8 bits, or possibly less). > Would it be possible, do you think, to use the horizontal vbl > softswitch (thinks its around $C02E or $C02F) - is this sufficiently > random? I like to use the soft switches for my randon routines. These "air-bytes" are constantly and semi-randomly changing. Try this: LDA #00 (not really necessary) LDX #FF EOR $C061 <-\ (joystick button #2 I believe) ROR | DEX | BNE --------/ That puts a very random number in the Accumulator, does not take too much time, and is a very short piece of code. Don't just use the contents of a soft switch -- certain bit positions tend to stay at one state most of the time, so you will be getting the same (or near same) bit patterns every now and again. The shifting done above cures this problem. Need it more random? introduce an additional Yreg outer loop. I ran this on my //c 1000 times, and got a good distribution. Oh, and if you need less bits, just mask the unneeded ones out; if you need more, call the routine twice, once for low byte, once for high byte. later, Nathan