How to scramble the lines of a txt file

ExSan++

     1 ///---------Today's ExSan Code----------------------

     2 // How to scramble the lines of a txt  file

     3 const string dbFile = " ... stocki.txt";   // source

     4 string dbScrambledFile = " ... stockScrambled.txt";   // destination

     5 

     6 fstream ffrom, fto;

     7 vector fileLine;

     8 string line;

     9 unsigned short lineCounter(0);

    10 ffrom.open(dbFile, ios::in);

    11 if (!ffrom) {// source

    12    printf("Error! cant find this file");   

    13    return;

    14    exit(1);

    15 }

    16 do {

    17    getline(ffrom, line);   

    18    fileLine.push_back(line);

    19    ++lineCounter;

    20 } while (!ffrom.eof());

    21 ffrom.close();

    22 

    23 boost::random::uniform_int_distribution<> uniformRndInt{ 0, lineCounter - 1 }; //#include <

    24 

    25 fto.open(dbScrambledFile, ios::out);  // 

    26 for (unsigned short counter = 0; counter < lineCounter; counter++) {

    27    randNum = uniformRndInt(generator);   

    28    if (std::find(randIntVector.begin(), randIntVector.end(), randNum) != randIntVector.end())

    29       --counter;         

    30    else 

    31       randIntVector.push_back(randNum);

    32 }

    33 

    34 for (unsigned short i = 0; i < lineCounter; i++) {

    36    fto << fileLine[(unsigned short)randIntVector[i]];

    37    if (i != lineCounter - 1) fto << endl;  //no jump to an empty line at the end

    38    else break;

    39 }

    40 fto.close();

    41 

    42 ////---------input file

    43 AVPTi

    44 BTCi

    45 GETYi

    46 CGEMYi

    47 CLFi

    48 ENVXi

    49 FQVLFi

    50 FTIi

    51 GFSi

    52 KIGRYi

    53 INDIi

    54 MGAMi

    55 NOVi

    56 NWGi

    57 PGYi

    58 Xi

    59 

    60 ////---------output file

    61 GETYi

    62 FQVLFi

    63 AVPTi

    64 Xi

    65 NWGi

    66 INDIi

    67 PGYi

    68 MGAMi

    69 BTCi

    70 FTIi

    71 GFSi

    72 ENVXi

    73 KIGRYi

    74 NOVi

    75 CGEMYi

    76 CLFi

    77 

    78 

    79 

    80 //----------------------------------------------

    81 ////---------input file

    82 ///---------Today's ExSan Code----------------------

    83 // How to scramble the lines of a txt  file

    84 const string dbFile = " ... stocki.txt";   // source

    85 string dbScrambledFile = " ... stockScrambled.txt";   // destination

    86 

    87 fstream ffrom, fto;

    88 vector fileLine;

    89 string line;

    90 unsigned short lineCounter(0);

    91 ffrom.open(dbFile, ios::in);

    92 if (!ffrom) {// source

    93    printf("Error! cant find this file");

    94    return;

    95    exit(1);

    96 }

    97 do {

    98    getline(ffrom, line);

    99    fileLine.push_back(line);

   100    ++lineCounter;

   101 } while (!ffrom.eof());

   102 ffrom.close();

   103 

   104 boost::random::uniform_int_distribution<> uniformRndInt{ 0, lineCounter - 1 }; //#include <

   105 

   106 fto.open(dbScrambledFile, ios::out);  // 

   107 for (unsigned short counter = 0; counter < lineCounter; counter++) {

   108    randNum = uniformRndInt(generator);

   109    if (std::find(randIntVector.begin(), randIntVector.end(), randNum) != randIntVector.end())

   110       --counter;

   111    else

   112       randIntVector.push_back(randNum);

   113 }

   114 

   115 for (unsigned short i = 0; i < lineCounter; i++) {

   116    index = randIntVector[i];

   117    fto << fileLine[(unsigned short)randIntVector[i]];

   118    if (i != lineCounter - 1) fto << endl;  //no jump to an empty line at the end

   119    else break;

   120 }

   121 fto.close();

   122 

   123 ////---------output file

   124 else break;

   125 

   126 if (!ffrom) {// source

   127    fto << fileLine[(unsigned short)randIntVector[i]];

   128    fstream ffrom, fto;

   129    ffrom.open(dbFile, ios::in);

   130    ++lineCounter;

   131 } while (!ffrom.eof());

   132 string dbScrambledFile = " ... stockScrambled.txt";   // destination

   133 if (i != lineCounter - 1) fto << endl;  //no jump to an empty line at the end

   134 randIntVector.push_back(randNum);

   135 }

   136 }

   137 return;

   138 fto.close();

   139 fto.open(dbScrambledFile, ios::out);  // 

   140 string line;

   141 if (std::find(randIntVector.begin(), randIntVector.end(), randNum) != randIntVector.end())

   142 }

   143 printf("Error! cant find this file");

   144 

   145 

   146 vector fileLine;

   147 fileLine.push_back(line);

   148 // How to scramble the lines of a txt  file

   149 index = randIntVector[i];

   150 

   151 for (unsigned short i = 0; i < lineCounter; i++) {

   152    exit(1);

   153    boost::random::uniform_int_distribution<> uniformRndInt{ 0, lineCounter - 1 }; //#include 

   154    unsigned short lineCounter(0);

   155    getline(ffrom, line);

   156    ///---------Today's ExSan Code----------------------

   157    randNum = uniformRndInt(generator);

   158    do {

   159       --counter;

   160       for (unsigned short counter = 0; counter < lineCounter; counter++) {

   161          const string dbFile = " ... stocki.txt";   // source

   162          ffrom.close();

   163    else

   164 

   165 

   166 

   167 

Polulating ExSan with Market Data Tick by Tick
Previous         Low Latency Systematic Trading Algorithm         Next

+ + C   E x S a n   C + +
D o   N o t   A c c e p t   D e f a u l t s
T h i n k   D i f f e r e n t

Flag Counter

Comments

Popular posts from this blog

This code deletes n columns from ExSan(n, m) ---> ExSan(p, q-n)

This code adds one column to ExSan Grid // ExSan(n, m) ----> Exsan(n, m + 1)