Random Number in CPP
#include<iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int random(int min, int max)
{
return min + rand()%(max-min+1);
}
int main()
{
//int i = 0, r;
// int max,min;
/* cout<<"Nhap max :";
cin>> max;
cout<<"Nhap min :";
cin>> min;
*/
// so a: min 1 chu so
// ma
int min =0;
int max = 500;
int ketQua = min;
int soLuongGhep = 1;
if(max/10000 > 0 )
{
soLuongGhep = 5;
}
else if(max/1000 > 0 )
{
soLuongGhep = 4;
}
else if(max/100 > 0 )
{
soLuongGhep = 3;
}
else if(max/10 > 0 )
{
soLuongGhep = 2;
}
cout<<"so luong ghep:"<<soLuongGhep;
while(ketQua <= min | ketQua > 500)
{
// ghep:
// So hang nghin:
int chucNghin = 0, nghin = 0, tram=0, chuc= 0, donvi = 0;
switch (soLuongGhep){
case 5: {
srand(time(NULL));
chucNghin = rand()%10;
nghin = rand()%10;
tram = rand()%10;
chuc = rand()%10;
donvi = rand()%10;
break;
}
case 4: {
srand(time(NULL));
nghin = rand()%10;
tram = rand()%10;
chuc = rand()%10;
donvi = rand()%10;
break;
}
case 3: {
srand(time(NULL));
tram = rand()%10;
chuc = rand()%10;
donvi = rand()%10;
break;
}
default: {
break;
}
}
ketQua = tram * 100 + chuc * 10 + donvi;
}
cout<<endl<<ketQua;
return 0;
}