Solved

Random numbers..to be or not to be?

Posted on 1998-11-04
9
310 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
  • 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

An article on effective troubleshooting
Data breaches are on the rise, and companies are preparing by boosting their cybersecurity budgets. According to the Cybersecurity Market Report (http://www.cybersecurityventures.com/cybersecurity-market-report), worldwide spending on cybersecurity …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

806 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