Solved

Random Numbers In Codewarrior

Posted on 2000-02-18
4
527 Views
Last Modified: 2010-08-05
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
Comment
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
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Expert Comment

by:My name is Mud
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

by:Alisher_N
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

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

Author Comment

by:Vriaeliss
ID: 2541127
Adjusted points to 100
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

The conference as a whole was very interesting, although if one has to make a choice between this one and some others, you may want to check out the others.  This conference is aimed mainly at government agencies.  So it addresses the various compli…
Let’s face it: one of the reasons your organization chose a SaaS solution (whether Microsoft Dynamics 365, Netsuite or SAP) is that it is subscription-based. The upkeep is done. Or so you think.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question