You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by hz...@apache.org on 2018/04/25 16:27:12 UTC
[2/4] trafodion git commit: [TRAFODION-3042] Switch to
nanosecond-resolution time
[TRAFODION-3042] Switch to nanosecond-resolution time
Getting ready for the day where we can do two RAND() calls
in a microsecond - hopefully soon :-)
Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/4f834729
Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/4f834729
Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/4f834729
Branch: refs/heads/master
Commit: 4f834729efa2c9ae74922f1f32226a29b6f8d7d0
Parents: 36e21b2
Author: Hans Zeller <hz...@apache.org>
Authored: Tue Apr 24 22:01:37 2018 +0000
Committer: Hans Zeller <hz...@apache.org>
Committed: Tue Apr 24 22:01:37 2018 +0000
----------------------------------------------------------------------
core/sql/exp/exp_function.cpp | 42 ++++++--------------------------------
1 file changed, 6 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafodion/blob/4f834729/core/sql/exp/exp_function.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_function.cpp b/core/sql/exp/exp_function.cpp
index 5ece196..109e06d 100644
--- a/core/sql/exp/exp_function.cpp
+++ b/core/sql/exp/exp_function.cpp
@@ -51,6 +51,7 @@
#include <string.h>
#include <stdio.h>
#include <uuid/uuid.h>
+#include <time.h>
#include "NLSConversion.h"
#include "nawstring.h"
@@ -5937,45 +5938,14 @@ void ExFunctionRandomNum::initSeed(char *op_data[])
// Pick an initial seed. According to the reference given below
// (in the eval function), all initial seeds between 1 and
- // 2147483646 are equally valid. So, we just need to pick one
+ // 2147483647 are equally valid. So, we just need to pick one
// in this range. Do this based on a timestamp.
+ struct timespec seedTime;
- // Use ex_function_current to get timestamp.
- //
- char currBuff[32];
- char *opData[1];
- opData[0] = currBuff;
- ex_function_current currentFun;
- currentFun.eval(&opData[0], 0, 0);
+ clock_gettime(CLOCK_REALTIME, &seedTime);
- // Extract year, month, etc.
- //
- char *p = currBuff;
- short year = *((short*) p);
- p += sizeof(short);
- char month = *p++;
- char day = *p++;
- char hour = *p++;
- char minute = *p++;
- char second = *p++;
- Lng32 fraction = *((Lng32*) p);
-
- // Local variables year, ..., fraction are now initialized.
- // From the values of these variables, generate a seed in the
- // desired range.
-
- Lng32 x = year * month * day;
- if (hour) x *= hour;
- p = (char*) &x;
-
- assert(sizeof(Lng32)==4);
-
- p[0] |= (second<<1);
- p[1] |= (minute<<1);
- p[2] |= (minute<<2);
- p[3] |= second;
-
- seed_ = x + fraction;
+ seed_ = (Int32) (seedTime.tv_sec % 2147483648);
+ seed_ ^= (Int32) (seedTime.tv_nsec % 2147483648L);
// Go through one step of a linear congruential random generator.
// (https://en.wikipedia.org/wiki/Linear_congruential_generator).