title: How can I use math.random but only for certain values?
body: <p>Here's what I have (it's just an excerpt from my entire code):</p>
  
  <pre><code>int num = (int) Math.random()*100;
      switch(num)
      {
      case 0 : compChoice = "R";break;
      case 1 : compChoice = "P";break;
      case 2 : compChoice = "S";break;
      }
  </code></pre>
  
  <p>How can I get it to only come up with a random number of 0, 1, or 2?</p>
  
  <p>in a return statement I have later on, it says that the letter that is acquired here results in a "null"</p>
  
  <p>Here's the entire code if it helps:</p>
  
  <pre><code>import java.util.Scanner;
  import static java.lang.System.*;
  
  public class RockPaperScissors
  {
  private String playChoice;
  private String compChoice;
  
  public RockPaperScissors()
  {
  
  
  
  }
  
  public RockPaperScissors(String player)
  {
      playChoice = player;
  }
  
  public void setPlayers(String player)
  {
      playChoice = player;
      int num = (int) Math.random()*100 %3;
      switch(num)
      {
      case 0 : compChoice = "R";break;
      case 1 : compChoice = "P";break;
      case 2 : compChoice = "S";break;
      }
      out.print(compChoice);
  }
  
  public String determineWinner()
  {
      String winner="";
  
      if(playChoice == "R")
      {
          switch(compChoice)
          {
          case "R" : winner = "!Draw Game!";break;
          case "P" : winner = "!Computer wins &lt;&lt;Paper Covers Rock&gt;&gt;!";break;
          case "S" : winner = "!Player wins &lt;&lt;Rock Breaks Scissors&gt;&gt;!";break;
          }
      }
      else if(playChoice == "P")
      {
          switch(compChoice)
          {
          case "R" : winner = "!Player wins &lt;&lt;Paper Covers Rock&gt;&gt;!";break;
          case "P" : winner = "!Draw Game!";break;
          case "S" : winner = "!Computer wins &lt;&lt;Scissors Cuts Paper&gt;&gt;!";break;
          }
      }
      else if(playChoice == "S")
      {
          switch(compChoice)
          {
          case "R" : winner = "!Computer wins &lt;&lt;Rock Breaks Scissors&gt;&gt;!";break;
          case "P" : winner = "!Player wins &lt;&lt;Scissors Cuts Paper&gt;&gt;!";break;
          case "S" : winner = "!Draw Game!";break;
          }
      }
      return winner;
  }
  
  public String toString()
  {
      String output="";
  
      output = "player had " + playChoice + "\n computer had " + compChoice + "\n " + determineWinner();
  
      return output;
  }
  }
  </code></pre>
  
  <p>Here's my runner class since someone pointed out I'm not calling any method anywhere:</p>
  
  <pre><code>import java.util.Scanner;
  import static java.lang.System.*;
  
  public class Lab10d
  {
  public static void main(String args[])
  {
      Scanner keyboard = new Scanner(System.in);
      char response;
  
      //add in a do while loop after you get the basics up and running
  
          String player = "";
  
          out.print("Rock-Paper-Scissors - pick your weapon [R,P,S] :: ");
  
          //read in the player value
          player = keyboard.next();
  
          RockPaperScissors game = new RockPaperScissors(player);
          game.determineWinner();
          out.println(game);
              while(response == response)
      {
          out.print("Rock-Paper-Scissors - pick your weapon [R,P,S] :: ");
          player = keyboard.next();
          game.setPlayers(player);
          game.determineWinner();
          out.println(game + "\n");
          out.println("would you like to play again? (y/n):: ");
          response = (char) keyboard.next();
  
  
  
  
      }
  
  }
  }
  </code></pre>