Wednesday, 22 August 2012

Return random symbol (C++)

This function will return random symbol from '0' to '9' or 'A' to 'Z' or 'a' to 'z'
char Random(){

    int num = rand()%91;
    while(true){
        if(num > 47 && num < 58) // 0 to 9
            break;
        if(num > 64 && num < 91) // A to Z
            break;
        if(num > 96 && num < 123) // a to z
            break;
        num = rand()%91;
    }
    return num;

}

No comments:

Post a Comment