Solved

About the turbo pascal random number  generator

Posted on 1998-12-02
1
1,609 Views
Last Modified: 2010-10-05
What is the explicit definition of the linear congruential random number generator used in turbo pascal, i. e., what are its multiplicative constant and its modulus?
0
Comment
Question by:amitapal
[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
1 Comment
 
LVL 4

Accepted Solution

by:
jack_p50 earned 50 total points
ID: 1216268
Here are how TP6 and TP7 random works :


const
  rseed: longint = 0;

procedure randomize67;      {TP 6.0 & 7.0 seed generator}
begin
  reg.ah:=$2c;
  msdos(reg);    {get time: ch=hour,cl=min,dh=sec,dl=sec/100}
  rseed:=reg.dx;
  rseed:=(rseed shl 16) or reg.cx;
end;

function rand_word6(x: word): word;    {TP 6.0 RNG: word}
begin
  rseed:=rseed*134775813+1;
  rand_word6:=(rseed shr 16) mod x;
end;

function rand_word7(x: word): word;    {TP 7.0 RNG: word}
begin
  rseed:=rseed*134775813+1;
  rand_word7:=((rseed shr 16)*x+((rseed and $ffff)*x shr 16)) shr 16;
end;

function rand_real67: real;    {TP 6.0 & 7.0 RNG: real}
begin
  rseed:=rseed*134775813+1;
  if rseed<0 then rand_real67:=rseed/4294967296.0+1.0 else
  rand_real67:=rseed/4294967296.0;
end;
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
We take a look at some of the most common obstacles that IT teams run into as they work relentlessly to keep all the alarms and sirens from going off at once.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

717 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