Thursday, August 31, 2017

interesting programs


1. C code to generate you tube like random string
Example:
 https://www.youtube.com/watch?v=AB2rwvDXc-Y
https://www.youtube.com/watch?v=YW57xBVEIP8

#include<stdio.h>
#include<string.h>

static const char alphanum[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
int stringLength = sizeof(alphanum) - 1;

char genRandom()  // Random string generator function.
{

    return alphanum[rand() % stringLength];
}

int main()
{
    char String[128]={0};
    int z;
    srand(time(0));
    for(z=0; z < 21; z++)
    {
        String[z] = genRandom();

    }
    printf("random string is : %s\n",String);
    return 0;

}
[tselva@bng-junos-d037 /b/tselva/bcopy/bk_copy_needed/copy-needed/work_tips_dir/sample_c_program]$ ./a.out
random string is : auoaP!MsZTEp9rsndUoEC

Ref:
http://www.cplusplus.com/forum/windows/88843/

Source code highligher:
http://hilite.me/

No comments:

Post a Comment