[SERVER-20727] Random.setRandomSeed() does not create a unique seed Created: 01/Oct/15  Updated: 20/Nov/15  Resolved: 12/Nov/15

Status: Closed
Project: Core Server
Component/s: Shell, Testing Infrastructure
Affects Version/s: 3.1.8
Fix Version/s: 3.2.0-rc3

Type: Bug Priority: Minor - P4
Reporter: Jonathan Abrahams Assignee: Jonathan Reams
Resolution: Done Votes: 0
Labels: 32qa
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File random_seed-SERVER-20727.sh    
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

for (i=0;i<3;i++) { print(new Date()); Random.setRandomSeed(); }

Thu Oct 01 2015 17:03:00 GMT-0400 (EDT)
setting random seed: 1443733380232
Thu Oct 01 2015 17:03:00 GMT-0400 (EDT)
setting random seed: 1443733380232
Thu Oct 01 2015 17:03:00 GMT-0400 (EDT)
setting random seed: 1443733380233

Sprint: Build B (10/30/15), Build C (11/20/15)
Participants:

 Description   

The shell function Random.setRandomSeed() is not reliable to set a random seed, since it relies on new Date().getTime()), which is only a millisecond based value.



 Comments   
Comment by Githook User [ 12/Nov/15 ]

Author:

{u'username': u'jbreams', u'name': u'Jonathan Reams', u'email': u'jbreams@mongodb.com'}

Message: SERVER-20727 Seed shell random numbers from SecureRandom
Branch: master
https://github.com/mongodb/mongo/commit/8eeed6d77edaf0b0f2b9834d60e5ea0d3aa8e050

Comment by Jonathan Abrahams [ 10/Nov/15 ]

Run the attached script and then issue:

grep -a3 Workloads /tmp/client.log

Then uncomment out the sleep and rerun. Note that the first test is almost always the same. There's not enough randomization happening.

Comment by Jonathan Reams [ 10/Nov/15 ]

How were you using the randomSeed to generate a random list? The following snippet works for me:

Random.setRandomSeed();
 
var nums = []
var maxSize = 1000;
for(var i = 0; i < maxSize; i++) {
    var curNum = Random.rand();
    assert(!Array.contains(nums, curNum));
    nums.push(curNum);
}

Comment by Jonathan Abrahams [ 10/Nov/15 ]

I was using this in a similar script and it did not give me a unique value where the randomSeed was used to generate a random list. Without putting in an artificial delay the list was always the same.

Comment by Jonathan Reams [ 10/Nov/15 ]

jonathan.abrahams, Date.getTime() returns the milliseconds since the UNIX epoch (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime) - running a for loop of 3 items just happens to take less than a single millisecond. Is there a specific case where this was not sufficient?

Generated at Thu Feb 08 03:55:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.