Alan Kaminsky Department of Computer Science Rochester Institute of Technology 4486 + 2220 = 6706
Home Page

Simulation Simplified
1. A Dice Game
Class Dice01

import edu.rit.util.Random;
public class Dice01
   {
   public static void main
      (String[] args)
      throws Exception
      {
      if (args.length != 1) usage();
      long seed = Long.parseLong (args[0]);
      Random prng = Random.getInstance (seed);
      int win = 0;
      int die;
      do
         {
         ++ win;
         die = prng.nextInt (6) + 1;
         System.out.printf ("%d%n", die);
         }
      while (die != 6);
      System.out.printf ("Winnings = $%d%n", win);
      }

   private static void usage()
      {
      System.err.println ("Usage: java Dice01 <seed>");
      System.exit (1);
      }
   }
Alan Kaminsky Department of Computer Science Rochester Institute of Technology 4486 + 2220 = 6706
Home Page
Copyright © 2011 Alan Kaminsky. All rights reserved. Last updated 31-Aug-2011. Please send comments to ark­@­cs.rit.edu.