Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.apple2.programmer > #1120

Re: What to pass to srand()?

From "Bill Buckels" <bbuckels@mts.net>
Newsgroups comp.sys.apple2.programmer
Subject Re: What to pass to srand()?
Date 2014-01-18 17:32 -0600
Organization Aioe.org NNTP Server
Message-ID <lbf2u0$gc0$1@speranza.aioe.org> (permalink)
References <lbdebg$vce$1@news4.open-news-network.org> <1e96d0ad-4c14-4895-902f-3ada72306581@googlegroups.com> <lbeo68$7l3$1@news4.open-news-network.org> <lbeuuo$tka$1@news.xmission.com>

Show all headers | View raw


"Egan Ford" <datajerk@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 

Back to comp.sys.apple2.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

What to pass to srand()? Matt <matt@clickertraining.co.nz> - 2014-01-18 21:28 +1300
  Re: What to pass to srand()? Marco Verpelli <mverpelli@libero.it> - 2014-01-18 01:31 -0800
    Re: What to pass to srand()? Matt <matt@clickertraining.co.nz> - 2014-01-19 09:22 +1300
      Re: What to pass to srand()? Egan Ford <datajerk@gmail.com> - 2014-01-18 15:24 -0700
        Re: What to pass to srand()? "Bill Buckels" <bbuckels@mts.net> - 2014-01-18 17:32 -0600
          Re: What to pass to srand()? "Bill Buckels" <bbuckels@mts.net> - 2014-01-18 17:38 -0600
        Re: What to pass to srand()? Michael J. Mahon <mjmahon@aol.com> - 2014-01-18 18:26 -0600
          Re: What to pass to srand()? Egan Ford <datajerk@gmail.com> - 2014-01-19 14:33 -0700
            Re: What to pass to srand()? Michael J. Mahon <mjmahon@aol.com> - 2014-01-19 23:27 -0600
          Re: What to pass to srand()? Vladimir Ivanov <vladitx@XXXyahooXXX.com> - 2014-01-20 01:35 +0200
  Re: What to pass to srand()? gids.rs@sasktel.net - 2014-01-18 21:17 -0800
    Re: What to pass to srand()? Michael J. Mahon <mjmahon@aol.com> - 2014-01-19 11:15 -0600
      Re: What to pass to srand()? gids.rs@sasktel.net - 2014-01-19 21:19 -0800
        Re: What to pass to srand()? Michael J. Mahon <mjmahon@aol.com> - 2014-01-20 00:14 -0600

csiph-web