E
E
Evgeny Petryaev2018-10-04 22:15:41
C++ / C#
Evgeny Petryaev, 2018-10-04 22:15:41

How to get a random value from a vector?

There is such a vector, you need to randomize something like this vector[random]; where random from [0,vectordrum.size()]; so that it does not go beyond the vector values.

vector<string>vectordrum;
vectordrum.push_back("str1");
vectordrum.push_back("str2");
vectordrum.push_back("str3");
vectordrum.push_back("str4");
int min=0,max=vectordrum.size(),random;

srand(time(0));
for(int__ i=0;i<countdrums;i++)
    {
        glPushMatrix();
        glRotatef(rotate[i],1,0,0);
        for(int__ j=0;j<counttextureondrums;j++)
        {
      random = ((int__)((float__)rand() / RAND_MAX*(max_ - min_) + min_));
      glBindTexture(GL_TEXTURE_2D,/*GetTexture(drum[i][j]-4)*/image->IndexTexture[FindTexture(vectordrum[random]/*"auto4"*/)]);
            EnableTexture(i,j);
        }
        glPopMatrix();
    }

Another place to put the call to srand(time(0)); so that when the rand() function is called in the loop, different numbers are obtained, because I have the same

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question