[ 
https://issues.apache.org/jira/browse/TRAFODION-3042?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16451364#comment-16451364
 ] 

ASF GitHub Bot commented on TRAFODION-3042:
-------------------------------------------

GitHub user zellerh opened a pull request:

    https://github.com/apache/trafodion/pull/1539

    [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.
    
    Also switched from a microsecond to a nanosecond-based timestamp.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/zellerh/trafodion bug/R23a

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/trafodion/pull/1539.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1539
    
----
commit 36e21b2c9c722bbcb551c35a761f069811051ea0
Author: Hans Zeller <hzeller@...>
Date:   2018-04-24T21:39:16Z

    [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.

commit 4f834729efa2c9ae74922f1f32226a29b6f8d7d0
Author: Hans Zeller <hzeller@...>
Date:   2018-04-24T22:01:37Z

    [TRAFODION-3042] Switch to nanosecond-resolution time
    
    Getting ready for the day where we can do two RAND() calls
    in a microsecond - hopefully soon :-)

----


> RAND() function is not always random
> ------------------------------------
>
>                 Key: TRAFODION-3042
>                 URL: https://issues.apache.org/jira/browse/TRAFODION-3042
>             Project: Apache Trafodion
>          Issue Type: Bug
>          Components: sql-exe
>    Affects Versions: 2.2.0
>            Reporter: Hans Zeller
>            Assignee: Hans Zeller
>            Priority: Major
>
> When trying the RAND() function, I found that it does not always behave as I 
> would expect. I tried this example:
> {noformat}
> >>select rand(), rand(), rand() from dual;
> (EXPR)      (EXPR)      (EXPR)    
> ----------  ----------  ----------
>   78242471    78511383    78612225
> --- 1 row(s) selected.
> >>select rand(), rand(), rand() from dual;
> (EXPR)      (EXPR)      (EXPR)    
> ----------  ----------  ----------
> 1589208276  1589460381  1589561223
> --- 1 row(s) selected.
> >>select rand(), rand(), rand() from dual;
> (EXPR)      (EXPR)      (EXPR)    
> ----------  ----------  ----------
> 134371215   134724162   134858618
> --- 1 row(s) selected.
> >>
> {noformat}
> So, it seems that if we call rand() within a very short time, the value will 
> be non-random.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to