Tuesday, February 21, 2012

Challenge 047’s Solution

The single statement that generates the random number object winner is:
 
int winner = new Random().nextInt(49) + 1;
 
−Phoenix

3 comments:

  1. How would you accomplish this same thing using the static method Math.random() ?

    ReplyDelete
  2. Using the method “Math.random()”, the statement could be rewritten as:

    int winner = (int)(50 * Math.random()) + 1;

    −Phoenix

    ReplyDelete
  3. 200 XPs awarded for this completion.

    ReplyDelete