Skip to content

Commit

Permalink
[webgui] do not use gRandom in webdisplay classes
Browse files Browse the repository at this point in the history
When required, instantiate TRandom3 instance directly.
Try to avoid interference with other tests relying on gRandom
  • Loading branch information
linev committed Nov 26, 2024
1 parent 8ed53a3 commit 2715bfe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
21 changes: 12 additions & 9 deletions gui/webdisplay/src/RWebDisplayHandle.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "RConfigure.h"
#include "TSystem.h"
#include "TRandom.h"
#include "TRandom3.h"
#include "TString.h"
#include "TObjArray.h"
#include "THttpServer.h"
Expand Down Expand Up @@ -563,7 +563,8 @@ std::string RWebDisplayHandle::ChromeCreator::MakeProfile(std::string &exec, boo
if (chrome_profile && *chrome_profile) {
profile_arg = chrome_profile;
} else {
gRandom->SetSeed(0);
TRandom3 rnd;
rnd.SetSeed(0);
profile_arg = gSystem->TempDirectory();
#ifdef _MSC_VER
char slash = '\\';
Expand All @@ -572,7 +573,7 @@ std::string RWebDisplayHandle::ChromeCreator::MakeProfile(std::string &exec, boo
#endif
if (!profile_arg.empty() && (profile_arg[profile_arg.length()-1] != slash))
profile_arg += slash;
profile_arg += "root_chrome_profile_"s + std::to_string(gRandom->Integer(0x100000));
profile_arg += "root_chrome_profile_"s + std::to_string(rnd.Integer(0x100000));

rmdir = profile_arg;
}
Expand Down Expand Up @@ -644,8 +645,8 @@ std::string RWebDisplayHandle::FirefoxCreator::MakeProfile(std::string &exec, bo
} else if (ff_profilepath && *ff_profilepath) {
profile_arg = "-profile "s + ff_profilepath;
} else if (ff_randomprofile > 0) {

gRandom->SetSeed(0);
TRandom3 rnd;
rnd.SetSeed(0);
std::string profile_dir = gSystem->TempDirectory();

#ifdef _MSC_VER
Expand All @@ -655,7 +656,7 @@ std::string RWebDisplayHandle::FirefoxCreator::MakeProfile(std::string &exec, bo
#endif
if (!profile_dir.empty() && (profile_dir[profile_dir.length()-1] != slash))
profile_dir += slash;
profile_dir += "root_ff_profile_"s + std::to_string(gRandom->Integer(0x100000));
profile_dir += "root_ff_profile_"s + std::to_string(rnd.Integer(0x100000));

profile_arg = "-profile "s + profile_dir;

Expand Down Expand Up @@ -1199,9 +1200,11 @@ bool RWebDisplayHandle::ProduceImages(const std::vector<std::string> &fnames, co
if (chrome_tmp_workaround) {
std::string homedir = gSystem->GetHomeDirectory();
auto pos = html_name.Last('/');
if (pos == kNPOS)
html_name = TString::Format("/random%d.html", gRandom->Integer(1000000));
else
if (pos == kNPOS) {
TRandom3 rnd;
rnd.SetSeed(0);
html_name = TString::Format("/random%d.html", rnd.Integer(1000000));
} else
html_name.Remove(0, pos);
html_name = homedir + html_name.Data();
gSystem->Unlink(html_name.Data());
Expand Down
10 changes: 5 additions & 5 deletions gui/webdisplay/src/RWebWindowsManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "TString.h"
#include "TApplication.h"
#include "TTimer.h"
#include "TRandom.h"
#include "TRandom3.h"
#include "TError.h"
#include "TROOT.h"
#include "TEnv.h"
Expand Down Expand Up @@ -534,13 +534,13 @@ bool RWebWindowsManager::CreateServer(bool with_http)
if ((http_timer > 0) && !IsUseHttpThread())
fServer->SetTimer(http_timer);

TRandom3 rnd;

if (http_port < 0) {
ntry = 0;
} else {

if (http_port == 0)
gRandom->SetSeed(0);

rnd.SetSeed(0);
if (http_max - http_min < ntry)
ntry = http_max - http_min;
}
Expand All @@ -558,7 +558,7 @@ bool RWebWindowsManager::CreateServer(bool with_http)
return false;
}

http_port = (int)(http_min + (http_max - http_min) * gRandom->Rndm(1));
http_port = (int)(http_min + (http_max - http_min) * rnd.Rndm(1));
}

TString engine, url;
Expand Down

0 comments on commit 2715bfe

Please sign in to comment.