[SERVER-61387] Random.setRandomSeed() prints the wrong seed Created: 10/Nov/21  Updated: 29/Oct/23  Resolved: 11/Nov/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 5.2.0

Type: Bug Priority: Major - P3
Reporter: David Percy Assignee: David Percy
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: QO 2021-11-15
Participants:

 Description   

This is a test-only bug.

When I run setRandomSeed() with no arguments, the seed it prints appears to be wrong, or not reproducible somehow. When I paste the seed back in I get something deterministic but not the same as the original run with no arguments.

After looking a JSSRand() I think the seed that is printed loses some precision when it's converted from int64_t to a Javascript number (a double).


ubuntu@ip-10-122-11-128:~/mongo$ build/debug/install/bin/mongo --nodb --eval 'Random.setRandomSeed(); print(Random.rand())'
MongoDB shell version v5.1.0-alpha-1440-gcab0aa7
setting random seed: 6952011769478614000
0.3131460341608944
ubuntu@ip-10-122-11-128:~/mongo$ build/debug/install/bin/mongo --nodb --eval 'Random.setRandomSeed(6952011769478614000); print(Random.rand())'
MongoDB shell version v5.1.0-alpha-1440-gcab0aa7
setting random seed: 6952011769478614000
0.31309103118094894
ubuntu@ip-10-122-11-128:~/mongo$ build/debug/install/bin/mongo --nodb --eval 'Random.setRandomSeed(6952011769478614000); print(Random.rand())'
MongoDB shell version v5.1.0-alpha-1440-gcab0aa7
setting random seed: 6952011769478614000
0.31309103118094894



 Comments   
Comment by Githook User [ 11/Nov/21 ]

Author:

{'name': 'David Percy', 'email': 'david.percy@mongodb.com', 'username': 'dpercy'}

Message: SERVER-61387 Make sure setRandomSeed() prints the exact value it chose
Branch: master
https://github.com/mongodb/mongo/commit/9e0211da72aa4a8526420fc02a78dff8bcb871d5

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