1 package gnu.brl; 2 3 7 import kawa.lang.*; 8 import gnu.mapping.Procedure1; 9 import gnu.mapping.WrongType; 10 import gnu.mapping.InPort; 11 import gnu.math.*; 12 13 public class random extends Procedure1 { 14 15 static java.util.Random prg = new java.util.Random (); 16 17 public final Object apply1 (Object arg1) 18 { 19 IntNum retval = new IntNum(); 20 21 if (arg1 instanceof IntNum) 23 { 24 IntNum.divide(IntNum.makeU(Math.abs(prg.nextLong()) >> 1), 25 (IntNum) arg1, null, retval, Numeric.FLOOR); 26 return retval; 27 } 28 29 if (arg1 instanceof InPort) 31 try 32 { 33 InPort i = (InPort)arg1; 34 prg.setSeed((long) 35 i.read() 36 + i.read() << 8 37 + i.read() << 16 38 + i.read() << 24); 39 i.close(); 40 return retval; 41 } 42 catch (java.io.IOException e) 43 { 44 throw new GenericError ("I/O exception in brl-random: " 45 + e.toString ()); 46 } 47 throw new WrongType (this, 1, arg1, "real"); 48 } 49 } 50 | Popular Tags |