CS 120     Jeff Horn                

Random Numbers in Java  (a general formula)

 

int x;    //  Declare x to be an integer.

x = (int)   (400 * Math.random()    );   //  This gives x a random int from 0 to 400.

                                                           //  Watch your parentheses and don't forget the semi-colon! 

x = (int) (600 * Math.random() );       //   This gives x a random int from 0 to 800.

x = 200+  (int) (600 * Math.random()  );  // This gives x a random int from 200 to 800.