TIP: Click on subject to list as thread! ANSI
echo: commo
to: ALL
from: CARL MORRIS
date: 1995-11-24 21:52:00
subject: Random number Generator

A while back I wrote some macros that did random numbers.  The best one 
generated 28000 random numbers.  Well, I haven't been absent from random 
number generation, but I did loose my macro :(.  I however, was working on 
another project when I finally came up with the answer to generating 65536 
different random numbers before repeating any of them.  I don't know if Fred 
has added a random macro function yet, but if he hasn't, I'm sure this 
essage
will show him how easy it is, as COMMO already has all the code to generate 
random numbers built in.
After I found the "formula" for 65536 random numbers, I relised the same 
"formula" could also be used to generate ... 4294967296 random numbers.
Now the worst of this is, I can't believe I have been using this formula in 
my programs for other things and never relised it!  Whats this formula I
found this time?  eh eh, 16 bit and 32 bit Cyclic Redundancy Checks.
CRC's will provide completely unique identification of all strings of data 
equal in size.  For a 16 bit CRC, a 2 byte string of data will always have a 
unique CRC, 4 bytes for 32 bit CRC.
COMMO already has CRC routines built in for Xmodem and Zmodem protocols.  As 
such, COMMO is already capable of generating random numbers.
How it works:  Lets say SEED is a variable the same length as the CRC.  SEED 
is set to any number you want.  A call to the random number generator builds 

CRC over the data area containing the SEED variable.  This is returned as the 
random number.  Before returing though SEED should be incremented by one 
ount
to provide another unique number on the next call.
4 billion unique numbers a few too many?  Not hard to over come.  Two other
variables are used to generate random numbers, a MAX, and a MIN.  A third 
variable is calculated from MAX and MIN called RANGE = MAX - MIN + 1.  The 
random number in full range is generated.  To get a smaller number, the 
modulus of the random number and RANGE is taken.  Then that number is added 
o
MIN to get the number in proper range....  ie:
RANDOM( MIN, MAX ) = (CRC( SEED++ ) MOD (MAX - MIN + 1) ) + MIN
I hope this helps people out some, and helps Fred even more.  I would write
a macro to show this, only the only way I know to generate CRCs requires an
XOR function which can't been done in COMMO macros, but maybe someone knows
how too?
Any questions, feel free to write, or netmail at 1:285/302 (routed).
Carl Morris
--- Renegade v10-05 Exp
---------------
* Origin: Hooper Connections -Home of SuperDir- 402-654-2102 (1:285/302)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.