Math question - Programmers Heaven

Howdy, Stranger!

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

Categories

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.