samedi 9 décembre 2017

generating different sets of random string c++

I have tried generating M different strings each of length N. Used the function below. But, when I call them with two different values of TYPE, I get the same strings as WORDS in TEST_WORDS also. What to do to have different sets of strings when I call the function different times in a single program run?

void rand_gen(int m,int n,int type)
{
time_t t;
srand((unsigned) time(&t));
for(int i=1; i<=m; i++)
{
    for(int j=0; j<n; j++)
    {
        int p=rand()%26;
        if(type==1)
        {
            words[i][j]='A'+p;
        }
        else
        {
            test_words[i][j]='A'+p;
        }

    }
}

}




Aucun commentaire:

Enregistrer un commentaire