Code to Generate random Name (10 character) and Credit Card (16 digits)
Code to Generate random Name (10 character) and Credit Card
(16 digits) and Save them to a .csv file along with Last_four digits of credit
card
Under Vuser_init.c Add the function random_
vuser_init()
{
return 0;
}
char buff[32] = "";
random_name(int length) {
int r,i;
srand((unsigned int)time(0)); //Seed number for rand()
r = rand() % 25 + 65; //uppercase for Initial Letter
buff[0] = (char)r;
//Loop to generate random small characters
for (i = 1; i < length; i++) {
// A-Z = 65-90 && a-z = 97-122
r = rand() % 26 + 97; //lowercase
buff[i] = (char)r;
}
return 0;
}
{
return 0;
}
char buff[32] = "";
random_name(int length) {
int r,i;
srand((unsigned int)time(0)); //Seed number for rand()
r = rand() % 25 + 65; //uppercase for Initial Letter
buff[0] = (char)r;
//Loop to generate random small characters
for (i = 1; i < length; i++) {
// A-Z = 65-90 && a-z = 97-122
r = rand() % 26 + 97; //lowercase
buff[i] = (char)r;
}
return 0;
}
Code which goes
into Action()
Action()
{
int i;
char *file1 = "C:\\temp\\sample.csv";
long filename1;
unsigned long num;
char randnum1[10], randnum2[20];
char name[20];
const char *last_four;
srand(time(NULL));
filename1=fopen(file1,"w");
fprintf(filename1,"Name, Credit_Card, Four_digits\n");
for(i=1;i<=2;i++)
{
random_name(10); //Pass the Length required as argument
lr_output_message("Name = %s",buff);
strcat(name,buff);
strcat(randnum1, lr_eval_string("{CC}"));
strcpy (randnum2, randnum1);
strcat(randnum2, lr_eval_string("{CC}"));
lr_output_message("Credit Card Number Generated is: %s", randnum2);
last_four = &randnum2[12];
lr_output_message ("The last 4 digits of Credit Card : %s", last_four);
fprintf(filename1,"%s,%s,%s\n",name,randnum2,last_four);//fprintf is used to enter some text into a file
memset(randnum1, '\0', sizeof(randnum1));
memset(randnum2, '\0', sizeof(randnum2));
memset(name, '\0', sizeof(name));
}
fclose(filename1);//flose is used to close the opened fie
return 0;
}
{
int i;
char *file1 = "C:\\temp\\sample.csv";
long filename1;
unsigned long num;
char randnum1[10], randnum2[20];
char name[20];
const char *last_four;
srand(time(NULL));
filename1=fopen(file1,"w");
fprintf(filename1,"Name, Credit_Card, Four_digits\n");
for(i=1;i<=2;i++)
{
random_name(10); //Pass the Length required as argument
lr_output_message("Name = %s",buff);
strcat(name,buff);
strcat(randnum1, lr_eval_string("{CC}"));
strcpy (randnum2, randnum1);
strcat(randnum2, lr_eval_string("{CC}"));
lr_output_message("Credit Card Number Generated is: %s", randnum2);
last_four = &randnum2[12];
lr_output_message ("The last 4 digits of Credit Card : %s", last_four);
fprintf(filename1,"%s,%s,%s\n",name,randnum2,last_four);//fprintf is used to enter some text into a file
memset(randnum1, '\0', sizeof(randnum1));
memset(randnum2, '\0', sizeof(randnum2));
memset(name, '\0', sizeof(name));
}
fclose(filename1);//flose is used to close the opened fie
return 0;
}
Output:
Starting action Action.
Action.c(20): Name = Wjaeiatthi
Action.c(27): Credit Card Number Generated is:
4418937762043482
Action.c(31): The last 4 digits of Credit Card : 3482
Action.c(20): Name = Vdvmudugth
Action.c(27): Credit Card Number Generated is:
4016207745512163
Action.c(31): The last 4 digits of Credit Card : 2163
Ending action Action.
Also sample.csv file is generated
under c:\temp which has below details:
Name
|
Credit_Card
|
Four_digits
|
Wjaeiatthi
|
4.41894E+15
|
3482
|
Vdvmudugth
|
4.01621E+15
|
2163
|
I use Random Name Generator for my dairy namer scrambler game, it helps me alot in it.
ReplyDelete