Advanced   Java   Services JAVA-Praktikum Back Next Up Home
Erweiterung der Klasse java.util.Random (Lösung)
// ------------ Random2.java  Erweiterung der Klasse java.util.Random ------------ \\

import java.util.Random;

public class Random2 extends java.util.Random
{
   public Random2()
   {
   }

   public Random2(long seed)
   {
      super(seed);
   }

   public byte nextByte()
   {
      return (byte)(nextInt(256));
   }

   public byte nextByte(byte b)
   {
      return (byte)(nextInt(b));
   }

   public short nextShort()
   {
      return (short)(nextInt(65536));
   }

   public short nextShort(short s)
   {
      return (short)(nextShort()%s) ;
   }

   public long nextLong(long lo)
   {
      return nextLong()%lo ;
   }

   public char nextChar()
   {
      return (char)(97 + nextInt(26));
   }

}  // end class Random2
Valid XHTML 1.0 Strict top Back Next Up Home