?
Solved

About the turbo pascal random number  generator

Posted on 1998-12-02
1
Medium Priority
?
1,613 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 150 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introducing Priority Question, our latest feature.
What's worse than having your data encrypted by ransomware? Getting attacked by a so-called "wiper," which simply destroys the data and offers you no hope of ever seeing it again.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

770 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