"Egan Ford" <
data...@gmail.com> wrote:
>Do you have any keyboard input before you need a random number?
Why not both a mouse and keboard loop to increment a range counter, then use
a modulus operator on the range counter as an index into a table of expected
valid values if those values are not necessarily sequential?
http://www.appleoldies.ca/MeToo.pdf
See the link above. When I ported my MeToo program from MS-DOS to the Apple
II (source is of course available from the Aztec C Website along with many
other sources) I did that just for fun.
As for the random number generator in Aztec C, here's the source but you
can't port it to cc65 because unlike Aztec C65 which also supports robust
inline assembly, cc65 does not support floating point math. I actually added
this to the Commdore 64 Aztec C65 version for another Aztec C User who
couldn't use cc65 because of its lack of math support:
/*
* Random number generator -
* adapted from the FORTRAN version
* in "Software Manual for the Elementary Functions"
* by W.J. Cody, Jr and William Waite.
*
*
http://en.bookfi.org/book/546944
*/
/*
NAME:
ran - random number generator
SYNOPSIS:
double ran()
DESCRIPTION:
ran returns as its value a random number between 0.0 and 1.0
*/
double ran()
{
static long int iy = 100001;
iy *= 125;
iy -= (iy/2796203) * 2796203;
return (double) iy/ 2796203.0;
}
double randl(x)
double x;
{
double exp();
return exp(x*ran());
}
Another approach you could do would be to roll your own random number
generator using the time in the no-slot clock as a seed.
Here's how you use the NSC which is already built into AppleWin:
Available for Download at the Aztec C Website at the following link:
http://www.aztecmuseum.ca/UTL.zip
This zip file contains a number of Apple IIe Utilities written in Aztec C
that run under the ProDOS Aztec C Shell.
Some of these utilites make use of the Apple IIe's No Slot Clock.
Perhaps a simpler NSC example is in the DHRYSTONE benchmark program for
Aztec C:
DHRYSTONE 1.1 for Apple IIe ProDOS 8 Aztec C65 3.2b cross-compiler:
http://www.aztecmuseum.ca/extras/DHRY.zip
Remember too that you can't put lips on a fish.
Bill