Solved

Random numbers..to be or not to be?

Posted on 1998-11-04
9
311 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

IT certifications are a concrete representation of continual learning on the part of the candidate.  Continual learning is necessary for the long term success of an IT professional, but are IT certifications the right path for you?
Many businesses neglect disaster recovery and treat it as an after-thought. I can tell you first hand that data will be lost, hard drives die, servers will be hacked, and careless (or malicious) employees can ruin your data.
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

840 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