Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Random Numbers In Codewarrior

Posted on 2000-02-18
Medium Priority
558 Views
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.
0
Question by:Vriaeliss
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 6

Expert Comment

ID: 2537681
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

LVL 3

Expert Comment

ID: 2537683
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

LVL 6

Accepted Solution

My name is Mud earned 400 total points
ID: 2538011
So...
0

Author Comment

ID: 2541127
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
Let's take a look into the basics of ransomware—how it spreads, how it can hurt us, and why a disaster recovery plan is important.
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
###### Suggested Courses
Course of the Month11 days, 1 hour left to enroll