Batch Mode : No randomization

Based on the program here, I changed just more line, everything else is the same

In batch mode, I don’t get the random sequence of 1s and 0s that I wanted, but if I run at the root prompt, I could. How can I sort this out?

#include <iostream>
using namespace std; 
void testRoot(){
int i=0;    
        do{
    
                cout << rand()%2 << "\t";
                i++;

        }while(i!=10);
}

output at root prompt :

0	1	1	1	1	0	0	1	1	0	root [1] .x testROOT.C
1	0	1	1	0	0	0	0	0	1	root [2] .x testROOT.C
0	1	1	0	0	0	1	1	1	1	root [3] .x testROOT.C
0	0	0	1	1	1	0	1	0	1	root [4] .x testROOT.C
1	1	1	0	1	0	0	1	0	1	root [5] .x testROOT.C
0	1	0	0	1	0	0	0	1	1	root [6] .x testROOT.C
1	0	1	0	1	0	1	1	1	0	root [7] .x testROOT.C
1	0	1	0	1	0	0	1	0	1	root [8] .x testROOT.C
0	0	0	0	0	1	1	0	1	0	root [9] .x testROOT.C

output as a batch program :

                 (c) 1995-2014, The ROOT Team |
 64   | Built for linux                                                |
 65   | From heads/master@v6-05-01-352-g03db581, Sep 15 2015, 14:48:39 |
 66   | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'     |
 67    ----------------------------------------------------------------
 68 
 69 
 70 Processing testROOT.C...
 71 0       1       1       1       1       0       0       1       1       0          ----------------------------------------------------------------
 72   | Welcome to ROOT 6.05/01                    http://root.cern.ch |
 73   |                                   (c) 1995-2014, The ROOT Team |
 74   | Built for linux                                                |
 75   | From heads/master@v6-05-01-352-g03db581, Sep 15 2015, 14:48:39 |
 76   | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'     |
 77    ----------------------------------------------------------------
 78 
 79 
 80 Processing testROOT.C...
 81 0       1       1       1       1       0       0       1       1       0          ----------------------------------------------------------------
 82   | Welcome to ROOT 6.05/01                    http://root.cern.ch |
 83   |                                   (c) 1995-2014, The ROOT Team |
 84   | Built for linux                                                |
 85   | From heads/master@v6-05-01-352-g03db581, Sep 15 2015, 14:48:39 |
 86   | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'     |
 87    ----------------------------------------------------------------
 88 
 89 
 90 Processing testROOT.C...
 91 0       1       1       1       1       0       0       1       1       0          ----------------------------------------------------------------

And also I would like to suppress the root banner.

Hi,

For the banner, use root -l macro.C.
To keep the random sequence under control, use a generator like TRandom3 and set the seed.

Danilo

Do not set non-zero seed if you want it really random (i.e. always use seed = 0). #include "TRandom.h" // gRandom #include <iostream> #include <cstdlib> // RAND_MAX void testRoot() { #if 1 /* 0 or 1 */ std::cout << gRandom->GetName() << " -> " << gRandom->GetTitle() << std::endl; #endif /* 0 or 1 */ gRandom->SetSeed(0); // make sure we're really random for (Int_t i = 0; i < 10; i++) { std::cout << Int_t(gRandom->Rndm() * (RAND_MAX)) % 2 << " "; } }

Perfect, thanks !

The banner adds up lots of lines in my standard output. How can I suppress it?

I tried adding the -l switch,
root -b -q -l testROOT.C but nothing happened.