trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hzel...@apache.org
Subject [1/4] trafodion git commit: [TRAFODION-3042] RAND() function is not always random
Date Wed, 25 Apr 2018 16:27:11 GMT
Repository: trafodion
Updated Branches:
  refs/heads/master dd051ea60 -> 06d38d5d3


[TRAFODION-3042] RAND() function is not always random

When called without a seed, we use a seed based on the
system timestamp. The random generator we use generates similar
output values for seeds that are close together. Adding another
randomization step to avoid that.


Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/36e21b2c
Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/36e21b2c
Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/36e21b2c

Branch: refs/heads/master
Commit: 36e21b2c9c722bbcb551c35a761f069811051ea0
Parents: 81fadbc
Author: Hans Zeller <hzeller@apache.org>
Authored: Tue Apr 24 21:39:16 2018 +0000
Committer: Hans Zeller <hzeller@apache.org>
Committed: Tue Apr 24 21:39:16 2018 +0000

----------------------------------------------------------------------
 core/sql/exp/exp_function.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/36e21b2c/core/sql/exp/exp_function.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_function.cpp b/core/sql/exp/exp_function.cpp
index a65c120..5ece196 100644
--- a/core/sql/exp/exp_function.cpp
+++ b/core/sql/exp/exp_function.cpp
@@ -5977,6 +5977,14 @@ void ExFunctionRandomNum::initSeed(char *op_data[])
 
       seed_ = x + fraction;
 
+      // Go through one step of a linear congruential random generator.
+      // (https://en.wikipedia.org/wiki/Linear_congruential_generator).
+      // This is to avoid seed values that are close to each other when
+      // we call this method again within a short time. The eval() method
+      // below doesn't handle seed values that are close to each other
+      // very well.
+      seed_ = (((Int64) seed_) * 1664525L + 1664525L) % 2147483648;
+
       if (seed_<0)
         seed_ += 2147483647;
       if ( seed_ < 1 ) seed_ = 1;


Mime
View raw message