pig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcove...@apache.org
Subject svn commit: r1397655 - in /pig/trunk: CHANGES.txt src/org/apache/pig/builtin/RANDOM.java
Date Fri, 12 Oct 2012 17:32:29 GMT
Author: jcoveney
Date: Fri Oct 12 17:32:29 2012
New Revision: 1397655

URL: http://svn.apache.org/viewvc?rev=1397655&view=rev
Log:
PIG-2965: RANDOM should allow seed initialization for ease of testing (jcoveney)

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/builtin/RANDOM.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1397655&r1=1397654&r2=1397655&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Fri Oct 12 17:32:29 2012
@@ -25,6 +25,8 @@ PIG-1891 Enable StoreFunc to make intell
 
 IMPROVEMENTS
 
+PIG-2965: RANDOM should allow seed initialization for ease of testing (jcoveney)
+
 PIG-2964: Add helper method getJobList() to PigStats.JobGraph. Extend visibility of couple
methods on same class (prkommireddi via billgraham)
 
 PIG-2579: Support for multiple input schemas in AvroStorage (cheolsoo via sms)

Modified: pig/trunk/src/org/apache/pig/builtin/RANDOM.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/RANDOM.java?rev=1397655&r1=1397654&r2=1397655&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/RANDOM.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/RANDOM.java Fri Oct 12 17:32:29 2012
@@ -19,6 +19,7 @@
 package org.apache.pig.builtin;
 
 import java.io.IOException;
+import java.util.Random;
 
 import org.apache.pig.EvalFunc;
 import org.apache.pig.data.Tuple;
@@ -31,10 +32,19 @@ import org.apache.pig.data.DataType;
  */
 @Nondeterministic
 public class RANDOM extends EvalFunc<Double>{
+    private Random r;
+
+    public RANDOM() {
+        r = new Random();
+    }
+
+    public RANDOM(String seed) {
+        r = new Random(Long.parseLong(seed));
+    }
 
 	@Override
 	public Double exec(Tuple input) throws IOException {
-		return Math.random();
+		return r.nextDouble();
 	}
 
     @Override



Mime
View raw message