电脑无法找到超过8000个独特字符串?

时间:2016-03-25 14:11:26

标签: c++ random

我写的小应用程序在二进制系统中绘制数字而没有重复。它适用于2,4,8位,但是当涉及到16个应用程序时,它找不到超过〜7,8k的组合。

以下是代码:

#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));
}

0 个答案:

没有答案