Random Division

Hello.

I am currently generating 2 random int numbers that will be used to divide between each other (num1 / num2). However, I only want numbers that (when divided), result in an integer number that does not contain a decimal (or remainder).

For example:
Good numbers: 6/3=2, 10/2=5, etc,
Bad numbers: 7/3=2.33, 8/6=1.33, etc.

All help is appreciated.

Thanks,



Answer this question

Random Division

  • HBergeron

    that should not be that hard. just check if number1%number2 is more than zero. If it is you will get a decimal number like 1.5456, if not you will get an int. Look here for the %-operator:

    http://cplus.about.com/od/learnin2/l/aa082504e.htm

    ralph



  • Matty4242

    Works great. Thanks Ralph!
  • Modhumita

    Hi,
    sorry for the silly question... why not do it the other way around

    What I mean is:
    get a random integer to represent the result of the division.
    get another random integer to represent the divisor.
    calculate the product of these two.

    The integer random numbers you are looking for are the second and third you obtain in this process.

    HTH
    --mc


  • Random Division