samedi 23 juin 2018

Generate random char/digit

I`m trying to found fastest way to generate random digit/char array.

char *randomGet(int num) {
    srand(time(NULL));
    const char ab[37] = { "0123456789ABCDEFGHIGKLMNOPQRSTUVWXYZ" };//Alphabet&Digit
    char *targ = new char[num];
    for (int i = 0; i < num; i++) {
        strcat(targ, ab[rand() % 38]);
    }
    return targ;
}

So far I've come up with this, but it does not work (argument of type char is incompatible with parameter of type const char *). Help me find the best solution to my problem. Ty.




Aucun commentaire:

Enregistrer un commentaire