summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2007-07-24 17:30:23 +0000
committermichelou <michelou@epfl.ch>2007-07-24 17:30:23 +0000
commitd8504784b821fb64f411adf7c551ee4646e5f99c (patch)
tree73534241fb12d0b55970d9addc319dde9ebd6048 /src/library
parent551e31ec7d1f3399cb1a0193f68268f292e96699 (diff)
downloadscala-d8504784b821fb64f411adf7c551ee4646e5f99c.tar.gz
scala-d8504784b821fb64f411adf7c551ee4646e5f99c.tar.bz2
scala-d8504784b821fb64f411adf7c551ee4646e5f99c.zip
added class scala.Random
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/BigInt.scala7
-rw-r--r--src/library/scala/Random.scala72
2 files changed, 75 insertions, 4 deletions
diff --git a/src/library/scala/BigInt.scala b/src/library/scala/BigInt.scala
index 0df92ec0ec..a24d141aec 100644
--- a/src/library/scala/BigInt.scala
+++ b/src/library/scala/BigInt.scala
@@ -11,7 +11,6 @@
package scala
import java.math.BigInteger
-import java.util.Random
/**
* @author Martin Odersky
@@ -62,7 +61,7 @@ object BigInt {
* with the specified bitLength.
*/
def apply(bitlength: Int, certaInty: Int, rnd: Random): BigInt =
- new BigInt(new BigInteger(bitlength, certaInty, rnd))
+ new BigInt(new BigInteger(bitlength, certaInty, rnd.self))
/** Constructs a randomly generated BigInt, uniformly distributed over the
* range 0 to (2 ^ numBits - 1), inclusive.
@@ -72,7 +71,7 @@ object BigInt {
* @return ...
*/
def apply(numbits: Int, rnd: Random): BigInt =
- new BigInt(new BigInteger(numbits, rnd))
+ new BigInt(new BigInteger(numbits, rnd.self))
/** Translates the decimal String representation of a BigInt into a BigInt.
*/
@@ -92,7 +91,7 @@ object BigInt {
/** Returns a positive BigInt that is probably prime, with the specified bitLength.
*/
def probablePrime(bitLength: Int, rnd: Random): BigInt =
- new BigInt(BigInteger.probablePrime(bitLength, rnd))
+ new BigInt(BigInteger.probablePrime(bitLength, rnd.self))
/** Implicit conversion from <code>int</code> to <code>BigInt</code>.
*/
diff --git a/src/library/scala/Random.scala b/src/library/scala/Random.scala
new file mode 100644
index 0000000000..6cc0d51ada
--- /dev/null
+++ b/src/library/scala/Random.scala
@@ -0,0 +1,72 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+// $Id: $
+
+
+package scala
+
+/**
+ * @author Stephane Micheloud
+ */
+class Random(val self: java.util.Random) {
+
+ /** Creates a new random number generator using a single long seed. */
+ 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) }
+
+}