?
Solved

Random number

Posted on 2001-07-03
7
Medium Priority
?
213 Views
Last Modified: 2010-04-06
i got a problem in a code i made here it is:

function altdom (Zero:integer) : integer;
var
TD:TDateTime;
ms:word;
i,res:integer;
 a,b:array[1..3] of word;
 begin
      TD:=Now;
     DecodeTime(TD,a[1],a[2],a[3],ms);
      DecodeDate(TD,b[1],b[2],b[3]);
    res:=3;
     for i:=1 to ms do // replace the 10 in what number u want...
begin
        res:=a[1]*a[2]*a[3]+res;
        res:=res*(b[1]+b[2]-b[3])-ms;
         res:=res*a[1]-ms;
res:=res div b[3];
     end;
if res=0 then res:=ms*b[2];
      res:=(res mod 5) + res ;
      result:=abs(res mod zero); <---- this is probably the ugly mistake but i dont know what i should do about it :(
 end;

procedure TForm1.Button1Click(Sender: TObject);
begin
sleep(altdom(0)*3);
label1.caption := inttostr(altdom(StrToInt(Label5.caption)));
end;

i want the program to choose a random number from label5.caption, and i dont wana use Random(number)
ex if label5.caption := 1000 then it  chooses a number from 1000 ex 526
0
Comment
Question by:TeChNiCh
[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
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 6250737
The line "sleep(altdom(0)*3)" passes 0 to altdom, so "result:=abs(res mod zero)" causes a 'division by zero' error.
0
 

Expert Comment

by:didil
ID: 6251028
dear TeChNiCh,
   
   maybe you already know the problem, that no number can be divide by 0, neither can be mod, so you cannot have the result for modifying the number by zero. try another number.
0
 

Author Comment

by:TeChNiCh
ID: 6252056
Well, i know that but i want it to be mod with label5.caption but i have no clue how... if u know how it can be done in any way... then please tell me, there is prolly a easier thing to do, but i dont wana use Random()
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 13

Expert Comment

by:Epsylon
ID: 6252081
Sorry, but I don't understand what you want.....

And what is the sleep(altdom(0)*3) doing there? It doen't make any sense to me.....
0
 
LVL 5

Accepted Solution

by:
TheNeil earned 400 total points
ID: 6252254
Is there any specific reason why you don't want to use Random()? As a psuedo random routine you're code looks Ok but as everyone else has already said, passing 0 to it will cause divide by zero problems. Why not simply add a check to specifically look for zero when you come to the MOD at the end:

IF Zero = 0
THEN
  Result := ABS(res MOD ms)
ELSE
  Result := ABS(res MOD Zero);

Although I've used your ms value it really doesn't matter which number you choose (it's a random number generator after all - I just thought using ms again would liven things up a little)

The Neil =:)
0
 

Author Comment

by:TeChNiCh
ID: 6252648
TheNeil has a pretty cool solution
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 6252973
Nope, The Neil just has an awful lot of luck. Thanks for the points

The Neil =:)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
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 …
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

765 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