vendredi 13 mars 2015

random between variables in C++?


First of all, I am still a beginner at learning programming. So please pardon me!


If i were to have 4 boolean values, let's say



a[0] = true
a[1] = false
a[2] = false
a[3] = true


and I were to randomize ONLY true values, how am I suppose to random them?


For example, since a[0] and a[3] is true, I can only random number 0 and 3. but random goes something like this



int random = rand() % 4 + 0;


So it will random from range 0-3. How am I suppose to do that with only true values? Please guide me along, thank you!




Aucun commentaire:

Enregistrer un commentaire