mercredi 17 février 2016

Why does starting value affect outcome of Seeded Random?

Trying to figure out why the starting value affects the seeded random in this code. I would expect for it to find the match at the same location for 12 character or more match no matter of the starting value for the seed, but it seems as though I am getting different results depending on the starting value of the seed which to me makes no sense. Anyone who why I am getting these results as shown from 0, 1, 2, and 3 for starting values when all 4 should flag the same values as a match to 12 more more characters.

Poor Key Finder 
Search for 12 or more matches
Searching through Key Values of **0** thru 1000000000

WARNING - Program Running Please Wait...

25% Complete

50% Complete

75% Complete

**Greater or Equal to = 12 ===== 923425024**

100% Complete

Completed = 1000000000


Press any key to continue . . .


Poor Key Finder  
Search for 12 or more matches
Searching through Key Values of **1** thru 1000000000

WARNING - Program Running Please Wait...

**Greater or Equal to = 12 ===== 204715678**

25% Complete

**Greater or Equal to = 12 ===== 346933630**

50% Complete

75% Complete

100% Complete

Completed = 1000000000


Press any key to continue . . .


Poor Key Finder  
Search for 12 or more matches
Searching through Key Values of **2** thru 1000000000

WARNING - Program Running Please Wait...

25% Complete

50% Complete

75% Complete

100% Complete

Completed = 1000000000


Press any key to continue . . .


Poor Key Finder  
Search for 12 or more matches
Searching through Key Values of **3** thru 1000000000

WARNING - Program Running Please Wait...

25% Complete

50% Complete

75% Complete

100% Complete

Completed = 1000000000


Press any key to continue . . .

Code:

#include <iostream>
#include <string>

int delay;
long long int counter1 = 0; // Add LL beyond 9 digits
long long int endcount = 0; // while loop end counter
long long int seed1 = 0;
int match2 = 0;
int ST = 0;
int flag = 0;
float progress = 0;
int step1 = 0;
int step2 = 0;
int step3 = 0;

int main()
{
    system("color b0");
    std::cout << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n";
    std::cout << "  Poor Key Finder Version 1.0\n";
    std::cout << "      Build 01/30/2016\n";
    std::cout << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\n";
    std::cout << " Enter Starting Key Value\n";
    std::cin >> counter1;
    std::cout << " Enter Ending Key Value\n";
    std::cin >> endcount;
    std::cout << " Enter Duplicate Character Counter Value\n";
    std::cin >> flag;
    system("cls");

    std::string str =
            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()_-+=?<>:\\/~.,;";
    std::string str2=
            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()_-+=?<>:\\/~.,;";
    system("@echo. Started on %date% at %time%>>LogKey.txt");
    system("color f0");
    std::cout << "Poor Key Finder - Search for " << flag
            << " or more matches \n";
    std::cout << "Searching through Key Values of " << counter1 << " thru "<<endcount<<"\n\ n";
    std::cout << "      WARNING - Program Running Please Wait...\n\n";
    while (counter1 <= endcount)
    {
        seed1 = counter1;
        srand(seed1);
        random_shuffle(str.begin(), str.end()); // Shuffle the string
        ST = 0;
        match2 = 0;

        progress = ((100 * counter1) / endcount);

        if (progress == 25)
        {
            step1++;
            if (step1 == 1)
            {
                std::cout << "25% Complete\n";
            }
            else
            {
            }
        }
        else if (progress == 50)
        {
            step2++;
            if (step2 == 1)
            {
                std::cout << "50% Complete\n";
            }
            else
            {
            }
        }
        else if (progress == 75)
        {
            step3++;
            if (step3 == 1)
            {
                std::cout << "75% Complete\n";
            }
            else
            {
            }
        }
        else if (endcount == counter1)
        {
            std::cout << "100% Complete\n";
        }
        else
        {
        }
        while (ST <= 85)
        {
            if (str[ST] == str2[ST])
            {
                match2++;
            }
            else
            {
            }
            ST++;
        }
        if (match2 >= flag)
        {

            std::cout << "Greater or Equal to = " << flag << " ===== " << seed1
                    << "\n";
        }
        else
        {
        }
        counter1++;
    }
    std::cout << "Completed = " << endcount << "\n\n\n";
    system("@echo. Ended on %date% at %time%>>LogKey.txt");
    system("pause");
    return 0;
}




Aucun commentaire:

Enregistrer un commentaire