title: How to use percentage weights with math.random
body: <p>Working on a homework assignment, honestly not even sure how to go about doing this. Any help is appreciated. Thanks!</p>
  
  <p>Assignment:
  A drunken person leaves a bar and heads home walking. It is observed that on average he steps forward 60% of the time, steps backward 30% of the time, and wobbles (no forward or backward movements) 10% of the time.</p>
  
  <p>His home is 50 feet (steps) from the bar. Write a Program called “PS1P2” that displays his movements on a typical night when he is walking home drunk. Your code should print a series of “Forward”, “Backward”, and “Wobble” words
  corresponding to his movements.</p>
  
  <p>Hint: You may use value generated by Math.random() to determine the person’s action
  in each step.</p>
  
  <p>Here is the code I have so far:</p>
  
  <pre><code>public static void main(String[] args) {
      double currentPos = 0;
      int houseDist = 50;
      int stepCounter = 0;
      double i;
  
      while(currentPos &lt; houseDist){
          i = Math.random();
          if(i &lt;= 0.6){
              System.out.println("Forward");
              currentPos++;
              stepCounter++;
          }
          if(i &lt;= 0.9){
              System.out.println("Backward");
              currentPos--;
              stepCounter++;
          }
          else
              System.out.println("Wobble");
      }
      System.out.println("Total steps: " + stepCounter);
      System.out.println("The house has been reached!");
  
  
  
  }//end main
  </code></pre>
  
  <p>Got it figured out! Didn't want this to seem like you guys were doing my homework for me, just needed somewhere to start. Thanks to those who did answer/help!</p>