# Random Numbers In Codewarrior

I can't find anywhere that know another way to generate random numbers in a PASCAL program other than "RANDOM (#)" which doesn't work...
If anyone knows anything, let me know.
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Systems EngineerCommented:
Since Randomize from pascal, seek a "Random number" generated by the time in the computer in an exact location in memory \$40:\$6C for the PC, in the MAC, you must know this exact location, and replace this values, if you don't know them, then you can buil a procedure to "Ask the Time" then sum the hours+Minutes+Seconds+100/sec, to get a randomize number.

{\$R-,S-,B-}
UNIT RANDNUM;

INTERFACE

Const
Rnd_M = 65521;
Rnd_C = 42000;
Rnd_A = 58417;
RndXn: Word = 16;

Procedure MyRandomizer;
Function MyRandomGen: Real;

IMPLEMENTATION

Procedure MyRandomizer;
Var
Rnd: Word Absolute \$40:\$6C; {***I think this is the problem***}
Begin
RndXn:=Rnd
End;

Function MyRandomGen: Real;
VAR
Tot,Frac: Real;
Begin
Tot:=(Rnd_A*RndXn+Rnd_C)/Rnd_M;
Frac:=(Tot-Trunc(Tot));
RndXn:=Trunc(Frac*Rnd_M);
MyRandomGen:=Frac;
End;

End.

Mod. version...

{\$R-,S-,B-}
UNIT RANDNUM;

INTERFACE

Const
Rnd_M = 65521;
Rnd_C = 42000;
Rnd_A = 58417;
RndXn: Word = 16;

Procedure MyRandomizer;
Function MyRandomGen: Real;

IMPLEMENTATION

USES
CRT;

Procedure MyRandomizer;
Var
Rnd: Word; (*Absolute \$40:\$6C; {***Eliminate this***}*)
HH,MM,SS,S100: Word;
Begin
GetTime(HH,MM,SS,S100);
RndXn:=HH+MM+SS+S100);
End;

Function MyRandomGen: Real;
VAR
Tot,Frac: Real;
Begin
Tot:=(Rnd_A*RndXn+Rnd_C)/Rnd_M;
Frac:=(Tot-Trunc(Tot));
RndXn:=Trunc(Frac*Rnd_M);
MyRandomGen:=Frac;
End;

End.
0
Commented:
why doesn't work ??

Randomize;
X := Round( 10 )+1; { get 1..10 }

by the way! if you work Mac (yack! ;) you may want to look at www.freepascal.org
guyz wrote nice compiler for all platforms (I use it on Linux) and it is fully compatible with Borland's Pascal & Delphi... try and you will not regret!

0
Systems EngineerCommented:
So...
0

Experts Exchange Solution brought to you by