I wrote little app that draws numbers in binary system without duplicates for me. It works perfectly for 2, 4, 8 bits but when it comes to 16 app can't find more than ~7,8k combinations.
Here is the code:
#include <iostream>
#include <vector>
#include <ctime>
#include <cstdlib>
#include <string>
#include <sstream>
#include <conio.h>
#include <math.h>
using namespace std;
string IntToString(int integer)
{
ostringstream ss;
ss<<integer;
string Converted = ss.str();
return Converted;
}
bool IsAlreadyDrawed(string what, vector <string> where)
{
for(int i=0; i<where.size(); i++)
{
if(where[i]==what) return true;
}
return false;
}
vector <string> FillIt(int HowManyBits)
{
vector <string> Randoms;
int random;
string lol;
do
{
for(int i=0; i<HowManyBits; i++) lol+=IntToString((rand()%2));
if(!IsAlreadyDrawed(lol,Randoms))
{
Randoms.push_back(lol);
cout<<"Pushing in "<<lol<<endl;
}
lol.clear();
}
while(Randoms.size()<pow(2,HowManyBits));
return Randoms;
}
void ShowIt(vector <string> What)
{
cout<<"\n";
for(int i=0; i<What.size();i++) cout<<i+1<<". "<<What[i]<<endl;
getch();
}
int main()
{
srand(time(0));
ShowIt(FillIt(16));
}
Aucun commentaire:
Enregistrer un commentaire