From 5d2441dd3ce3d91fd2fab6d913bdcaa3a088d498 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Mon, 4 May 2009 14:40:09 +0000 Subject: Fixes for #839 and #840, and removed some dupli... Fixes for #839 and #840, and removed some duplicated code. --- src/library/scala/Random.scala | 56 ++----------------------------------- src/library/scala/util/Random.scala | 9 ++++-- 2 files changed, 10 insertions(+), 55 deletions(-) (limited to 'src/library') diff --git a/src/library/scala/Random.scala b/src/library/scala/Random.scala index 4b44466b43..c24e2b2080 100644 --- a/src/library/scala/Random.scala +++ b/src/library/scala/Random.scala @@ -17,59 +17,9 @@ package scala * @deprecated Use class scala.util.Random instead. */ @deprecated -class Random(val self: java.util.Random) { - - /** Creates a new random number generator using a single long seed. */ +class Random(self: java.util.Random) extends util.Random(self) { def this(seed: Long) = this(new java.util.Random(seed)) - - /** Creates a new random number generator using a single integer seed. */ def this(seed: Int) = this(seed.toLong) - - /** Creates a new random number generator. */ - def this() = this(compat.Platform.currentTime) - - /** Returns the next pseudorandom, uniformly distributed boolean value - * from this random number generator's sequence. - */ - def nextBoolean(): Boolean = self.nextBoolean() - - /** Generates random bytes and places them into a user-supplied byte - * array. - */ - def nextBytes(bytes: Array[Byte]) { self.nextBytes(bytes) } - - /** Returns the next pseudorandom, uniformly distributed double value - * between 0.0 and 1.0 from this random number generator's sequence. - */ - def nextDouble(): Double = self.nextDouble() - - /** Returns the next pseudorandom, uniformly distributed float value - * between 0.0 and 1.0 from this random number generator's sequence. - */ - def nextFloat(): Float = self.nextFloat() - - /** Returns the next pseudorandom, Gaussian ("normally") distributed - * double value with mean 0.0 and standard deviation 1.0 from this - * random number generator's sequence. - */ - //def nextGaussian(): Double = self.nextGaussian() - - /** Returns the next pseudorandom, uniformly distributed int value - * from this random number generator's sequence. - */ - def nextInt(): Int = self.nextInt() - - /** Returns a pseudorandom, uniformly distributed int value between 0 - * (inclusive) and the specified value (exclusive), drawn from this - * random number generator's sequence. - */ - def nextInt(n: Int): Int = self.nextInt(n) - - /** Returns the next pseudorandom, uniformly distributed long value - * from this random number generator's sequence. - */ - def nextLong(): Long = self.nextLong() - - def setSeed(seed: Long) { self.setSeed(seed) } - + def this() = this(new java.util.Random()) } + diff --git a/src/library/scala/util/Random.scala b/src/library/scala/util/Random.scala index 021d0c182b..e37cb477ba 100644 --- a/src/library/scala/util/Random.scala +++ b/src/library/scala/util/Random.scala @@ -24,7 +24,7 @@ class Random(val self: java.util.Random) { def this(seed: Int) = this(seed.toLong) /** Creates a new random number generator. */ - def this() = this(compat.Platform.currentTime) + def this() = this(new java.util.Random()) /** Returns the next pseudorandom, uniformly distributed boolean value * from this random number generator's sequence. @@ -50,6 +50,7 @@ class Random(val self: java.util.Random) { * double value with mean 0.0 and standard deviation 1.0 from this * random number generator's sequence. */ + // XXX why is this the only method of java.util.Random to be commented out? //def nextGaussian(): Double = self.nextGaussian() /** Returns the next pseudorandom, uniformly distributed int value @@ -69,5 +70,9 @@ class Random(val self: java.util.Random) { def nextLong(): Long = self.nextLong() def setSeed(seed: Long) { self.setSeed(seed) } - } + +/** The object Random offers a default implementation + * of scala.util.Random. + */ +object Random extends Random \ No newline at end of file -- cgit v1.2.3