Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Random numbers..to be or not to be?

Posted on 1998-11-04
9
Medium Priority
?
318 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
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 150 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

While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
On September 18, Experts Exchange launched the first installment of the Help Bell, a new feature for Premium Members, Team Accounts, and Qualified Experts. The Help Bell will serve as an additional tool to help teams increase question visibility.
Video by: ITPro.TV
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

705 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