summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@epfl.ch>2008-07-30 08:42:35 +0000
committerLukas Rytz <lukas.rytz@epfl.ch>2008-07-30 08:42:35 +0000
commit66d53477ca8a60fc478d831992e0e467a10dc285 (patch)
tree5e84f052efc5c736739a1c4e77ba4293d735c001
parentd0063db3eaea7d5bd11d012b44d67af8b3bbe09a (diff)
downloadscala-66d53477ca8a60fc478d831992e0e467a10dc285.tar.gz
scala-66d53477ca8a60fc478d831992e0e467a10dc285.tar.bz2
scala-66d53477ca8a60fc478d831992e0e467a10dc285.zip
Move scala.Random -> scala.util.Random on .NET
-rw-r--r--src/dotnet-library/scala/Random.scala3
-rw-r--r--src/dotnet-library/scala/util/Random.scala74
2 files changed, 77 insertions, 0 deletions
diff --git a/src/dotnet-library/scala/Random.scala b/src/dotnet-library/scala/Random.scala
index 7d0b1be853..d389bcd7a7 100644
--- a/src/dotnet-library/scala/Random.scala
+++ b/src/dotnet-library/scala/Random.scala
@@ -13,7 +13,10 @@ package scala
/**
* @author Stephane Micheloud
+ *
+ * Use class <code>scala.util.Random</code> instead.
*/
+@deprecated
class Random(self0: System.Random) {
private var rnd = self0 // see setSeed(seed)
def self = rnd
diff --git a/src/dotnet-library/scala/util/Random.scala b/src/dotnet-library/scala/util/Random.scala
new file mode 100644
index 0000000000..a077e7853d
--- /dev/null
+++ b/src/dotnet-library/scala/util/Random.scala
@@ -0,0 +1,74 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+// $Id: Random.scala 14498 2008-04-04 12:12:27Z washburn $
+
+
+package scala.util
+
+/**
+ * @author Stephane Micheloud
+ */
+class Random(self0: System.Random) {
+ private var rnd = self0 // see setSeed(seed)
+ def self = rnd
+
+ /** Creates a new random number generator using a single long seed. */
+ def this(seed: Long) = this(new System.Random(seed.toInt))
+
+ /** Creates a new random number generator using a single integer seed. */
+ def this(seed: Int) = this(new System.Random(seed))
+
+ /** Creates a new random number generator. */
+ def this() = this(new System.Random(System.Environment.TickCount))
+
+ /** Returns the next pseudorandom, uniformly distributed boolean value
+ * from this random number generator's sequence.
+ */
+ def nextBoolean(): Boolean = (nextInt() & 0x1) == 1
+
+ /** Generates random bytes and places them into a user-supplied byte
+ * array.
+ */
+ def nextBytes(bytes: Array[Byte]) { rnd.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 = rnd.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 = nextDouble().toFloat
+
+ /** 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
+
+ /** Returns the next pseudorandom, uniformly distributed int value
+ * from this random number generator's sequence.
+ */
+ def nextInt(): Int = rnd.Next()
+
+ /** 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 = rnd.Next(0, n)
+
+ /** Returns the next pseudorandom, uniformly distributed long value
+ * from this random number generator's sequence.
+ */
+ def nextLong(): Long = nextInt().toLong // 2x nextInt() ?!
+
+ def setSeed(seed: Long) { rnd = new System.Random(seed.toInt) }
+
+}