Solved

Random numbers..to be or not to be?

Posted on 1998-11-04
9
307 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this step by step tutorial with screenshots, we will show you HOW TO: Enable SSH Remote Access on a VMware vSphere Hypervisor 6.5 (ESXi 6.5). This is important if you need to enable SSH remote access for additional troubleshooting of the ESXi hos…
We have come a long way with backup and data protection — from backing up to floppies, external drives, CDs, Blu-ray, flash drives, SSD drives, and now to the cloud.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now