1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
void generateCoupon(int columnCount)
{
int i,j,k,n;
int numbers[6] = {};
bool equal;
for (k=0 ; k<columnCount ; k++) {
for (i=0 ; i<6 ; i++ ) {
do
{
n=myRand();
equal=true; //If equal's value didn't change,loop will not be repeated for the current value of i.
for(j=0 ; j<i ;j++ ) {
if(numbers[j]==n) { //To check if any equal numbers obtained.
equal=false; //In case of equality,loop will be repeated until all numbers have distinct values.
break; //No need to go all through every other number.
}
}
} while (!equal);
numbers[j]=n;
cout<<numbers[j]<<" ";
}
cout<<endl;
}
}
void generateCouponWithConstant(int columnCount, int constantNumber, int constantColumnCount)
{
int i,j,k,n,l;
int numbers[6] = {};
bool equal;
for(k=0; k<constantColumnCount ; k++) {
cout<<constantNumber<<" ";
for (i=0 ; i<5 ; i++ ) { //i<5 because constant numbers is already displayed,since there are 5 numbers left to generate and display.
do
{
n=myRand();
equal=true; //If equal's value didn't change,loop will not be repeated for the current value of i.
for(j=0 ; j<i ;j++ ) {
if(numbers[j]==n || numbers[j]==constantNumber) { //To check if any equal numbers obtained.
equal=false; //In case of equality,loop will be repeated until all numbers have distinct values.
break; //No need to go all through every other number.
}
}
} while (!equal);
numbers[i]=n;
cout<<numbers[i]<<" ";
}
cout<<endl;
}
for(l=0; l<(columnCount - constantColumnCount) ; l++) {
for (i=0 ; i<6 ; i++ ) {
do
{
n=myRand();
equal=true; //If equal's value didn't change,loop will not be repeated for the current value of i.
for(j=0 ; j<i ;j++ ) {
if(numbers[j]==n) { //To check if any equal numbers obtained.
equal=false; //In case of equality,loop will be repeated until all numbers have distinct values.
break; //No need to go all through every other number.
}
}
} while (!equal);
numbers[i]=n;
cout<<numbers[i]<<" ";
}
cout<<endl;
}
}
void generateCouponWithRange(int columnCount, int lowerLimit, int upperLimit, int numberCount)
{
int i,m,n,j,k,l;
int numbers[6] = {};
bool equal;
for(j=0; j<columnCount ; j++) {
for(k=0 ; k<numberCount ; k++) {
do
{
n=myRand() % (upperLimit - lowerLimit + 1) + lowerLimit; //To obtain a number between lowerLimit to upperLimit.
equal=true; //If equal's value didn't change,loop will not be repeated for the current value of i.
for(i=0 ; i<k ;i++ ) {
if(numbers[i]==n) { //To check if any equal numbers obtained.
equal=false; //In case of equality,loop will be repeated until all numbers have distinct values.
break; //No need to go all through every other number.
}
}
} while (!equal);
numbers[i]=n;
cout<<numbers[i]<<" ";
}
for(l=numberCount ; l<6 ; l++) {
do
{
m=myRand();
equal=true; //If equal's value didn't change,loop will not be repeated for the current value of i.
for(i=0 ; i<l ;i++ ) {
if(numbers[i]==m) { //To check if any equal numbers obtained.
equal=false; //In case of equality,loop will be repeated until all numbers have distinct values.
break; //No need to go all through every other number.
}
}
} while (!equal);
numbers[i]=m;
cout<<numbers[i]<<" ";
}
cout<<endl;
}
}
void generateCouponWithDistance(int columnCount, int distance)
{
int a[6] = {0};
int i,j,k;
for(j=0 ; j<columnCount ; j++) {
while(true) {
a[0]=myRand();
for(i=1 ; i<6 ; i++) {
a[i]=a[i-1] + myRand() % (10 - distance) + distance; //Any numbers in array will have a difference as at least the distance and 9 at maxium.
}
if(a[5]<=49) break; //In case of overflow,start again.
}
for(k=0 ; k<6 ; k++) {
cout<<a[k]<<" ";
}
cout<<endl;
}
}
int myRand()
{
int random=rand() % 500 + 499; //A value between 500 to 999 is generated.
int random2=pow(random, 3); // Cube of the number is obtained to have a 9 digit number.
int randomFinal= getRange(random2, 3, 7); //A sub number is generated using getRange function.
return (randomFinal % 49) + 1; //Obtained a random number between 1 to 49 using modulus operation.
}
int getRange(int number, int startIndex, int endIndex)
{
int i,x,number1,number2,number3,number4;
x=number;
for (i=0 ; x>10 ; i++) {
x=x/10; // To determine how many digits number has,it is divided until it becomes smaller than 10.
}
number1=number/pow(10, i - startIndex + 2);
number2=number1*pow(10, i - startIndex + 2);
number3=number - number2;
number4=number3/pow(10, i - endIndex + 1);
return number4;
}
|