Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Math question

Hi.

I have 2 random numbers , and i want to check if i can divide them.

I used this code:

function make_random(string option):integer;
begin
randomize;
//option1 0 to 10
if (option='option1') then begin
result:=random(10);
end;
//more options..
end;

r:=make_random('option1');
r1:=make_random('option1');

r2 := r div r1;

if (r2<r) then r2:=2;

But its not the best solution...it returns 0 always.

I guess i have to fix something in my random rutine..


Any help?

Comments

  • amoeba3amoeba3 Posts: 15Member
    : Hi.
    :
    : I have 2 random numbers , and i want to check if i can divide them.
    :
    : I used this code:
    :
    : function make_random(string option):integer;
    : begin
    : randomize;
    : //option1 0 to 10
    : if (option='option1') then begin
    : result:=random(10);
    : end;
    : //more options..
    : end;
    :
    : r:=make_random('option1');
    : r1:=make_random('option1');
    :
    : r2 := r div r1;
    :
    : if (r2<r) then r2:=2;
    :
    : But its not the best solution...it returns 0 always.
    :
    : I guess i have to fix something in my random rutine..
    :
    :
    : Any help?
    :

    Hi,

    you can test whether one number is exactly divisible by another by using
    'mod'. If it is exactly divisible then the result would be zero.

    e.g [code] if value1 mod value2 = 0 then
    //do whatever[/code]





  • porodoroporodoro Posts: 230Member
    [b][red]This message was edited by porodoro at 2007-2-9 10:54:36[/red][/b][hr]
    : : Hi.
    : :
    : : I have 2 random numbers , and i want to check if i can divide them.
    : :
    : : I used this code:
    : :
    : : function make_random(string option):integer;
    : : begin
    : : randomize;
    : : //option1 0 to 10
    : : if (option='option1') then begin
    : : result:=random(10);
    : : end;
    : : //more options..
    : : end;
    : :
    : : r:=make_random('option1');
    : : r1:=make_random('option1');
    : :
    : : r2 := r div r1;
    : :
    : : if (r2 0) do begin
    a=2+new_random
    b=2+new_Random
    end;

    It returns nice numbers..


Sign In or Register to comment.