Solved

Random numbers..to be or not to be?

Posted on 1998-11-04
9
314 Views
Last Modified: 2010-04-16
I am using Turbo Pascal for Windows 1.5 and i can not get my random command to work like it did in TP7 for dos.  What can I do for random numbers in this case?
0
Comment
Question by:SupeRob
[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
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1215934
TP for Windows should still have the Randseed and Random. What do you mean by '...work like it did...'

Cheers,
Raymond.
0
 

Author Comment

by:SupeRob
ID: 1215935
I always used to use the Randomize command within TP7 but it doesn't work in TP 1.5.  If you know how to use RandSeed then please give me some sample code.
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1215936
Randseed is simply a variable you set one time in your program, before your first call to the random function.


example:

var x,y :word;

gettime(x,x,x,y);
randseed := y;


This will set the randseed to the 1/100 sec part of the system clock.  Using the system time is a good way to do it...you can use gettime (or some similar function available in TP for Windows...)


0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 3

Expert Comment

by:vikiing
ID: 1215937
The "Randomize" built-in procedure does (more or less) the same thing that Scrapdog suggests, 'cause it automatically uses the system clock to take a seed to feed the random generator.

Thus, your program can begin saying:

Begin
       Randomize;
       (the rest of stuff)

0
 

Author Comment

by:SupeRob
ID: 1215938
I am sorry to say but the Randomize feature does not work in any way shape or form on the TP 1.5 compiler and wincrt function.  Please thouroughly read my question before answering next time!
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 50 total points
ID: 1215939
Use RandSeed as ScrapDog describes (or by using the same number eg: RandSeed := 1000; to get consistent runs of numbers), then use Random(x) where x is the spread to get a random number.

Cheers,

Raymond.
0
 
LVL 3

Expert Comment

by:vikiing
ID: 1215940
I've read your question, Wilson; and I know you're using TP 1.5
But as I don't have that version of TP, I don't exactly what are the things that compiler accepts or not.
0
 

Expert Comment

by:AlexP
ID: 1215941
There is no random command, only a random function.

0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1215942
Thats right, use it like this:

var
x : integer;

x := random(1000); // returns random number between (1..1000) or (0..999) I forget which, the help will clarify.

Raymond.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Why do some people recommend buying business VoIP from an ISP? What are the benefits to my company? What are the costs?
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 …

631 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