Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-61387

Random.setRandomSeed() prints the wrong seed

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 5.2.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Fully Compatible
    • ALL
    • QO 2021-11-15

      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
      

            Assignee:
            david.percy@mongodb.com David Percy
            Reporter:
            david.percy@mongodb.com David Percy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: