예제 #1
0
serverInfo *CreateServer(int length)
{
  serverInfo *pServer = calloc(sizeof(serverInfo));
  pServer->name = GenerateRandomString(length);
  pServer->instances = NewList(LIST_INSTANCE);
  return pServer;
}
예제 #2
0
instanceInfo *CreateInstance(int length)
{
  instanceInfo *pInstance = calloc(sizeof(instanceInfo));
  pInstance->name = GenerateRandomString(length);
  pInstance->port = GenerateRandomNumber(0, 65535);
  pInstance->adminPortOffset = GetNextAdminPort();
  return pInstance;
}
예제 #3
0
void MainWidget::on_uploadButton_clicked()
{
    QString format = "png";
    QString fileName = QDate::currentDate().toString("yyMMdd") + GenerateRandomString(4) + "." + format;
    bool ok = originalPixmap.save(fileName, format.toAscii());
    if (ok) {
        qDebug() << fileName;
        qiniuup(fileName);
        QFile::remove(fileName);

        QString url = "http://aprilshot.qiniudn.com/" +  fileName;
        QClipboard *cb = QApplication::clipboard();
        cb->setText(url);
        trayIcon->showMessage("The image URL has copied to your clipboard.", url,
                              QSystemTrayIcon::NoIcon,
                              5 * 1000);

    }
}
예제 #4
0
const bool AlternateCaptcha1::Generate()
{
	if(m_fonts.size()==0)
	{
		return false;
	}

	std::string puzzlestring=GenerateRandomString(5);
	FreeImage::Bitmap tempchar(50,50,32);
	tempchar.SetTransparent();
	FreeImage::Bitmap bmp(110,50,32);
	bmp.SetTransparent();

	m_solution.clear();
	m_puzzle.clear();

	// draw the text
	if(m_fonts.size()>0)
	{
		for(int i=0; i<puzzlestring.size(); i++)
		{
			RGBQUAD black;
			black.rgbRed=0;
			black.rgbGreen=0;
			black.rgbBlue=0;
			int xoffset=(i*20)-(5+(rand()%5));
			int yoffset=(rand()%20)-10;
			int fontnum=rand()%m_fonts.size();
			FreeImage::Bitmap charbmp=m_fonts[fontnum].Char(puzzlestring[i]);

			tempchar.SetTransparent();
			tempchar.ClearTransparent();
			tempchar.BlitTrans(charbmp,25-(charbmp.Width()/2),25-(charbmp.Height()/2),0,0,charbmp.Width(),charbmp.Height());
			tempchar.Rotate((rand()%60)-30,0,0,25,25);

			bmp.BlitTrans(tempchar,xoffset,yoffset,0,0,50,50);
		}
	}

	//place some random lines
	RGBQUAD white;
	white.rgbRed=255;
	white.rgbGreen=255;
	white.rgbBlue=255;
	white.rgbReserved=255;
	int numlines=(rand()%5)+5;
	for(int i=0; i<numlines; i++)
	{
		// draw 4 short lines very close to each other
		int x1[4];
		int y1[4];
		int x2[4];
		int y2[4];

		x1[0]=rand()%bmp.Width();
		y1[0]=rand()%bmp.Height();
		x2[0]=x1[0]+(rand()%40)-20;
		y2[0]=y1[0]+(rand()%40)-20;

		for(int i=1; i<4; i++)
		{
			x1[i]=x1[i-1]+rand()%3-1;
			y1[i]=y1[i-1]+rand()%3-1;
			x2[i]=x2[i-1]+rand()%3-1;
			y2[i]=y2[i-1]+rand()%3-1;
		}

		for(int i=0; i<4; i++)
		{
			bmp.Line(x1[i],y1[i],x2[i],y2[i],white);
		}
	}

	// make output a little wavy
	int offset=rand()%10000;
	for(int y=0; y<bmp.Height(); y++)
	{
		double shift=sin((double)(y+offset)/3.0);
		bmp.HorizontalOffset(y,shift);
	}

	m_solution.clear();
	m_solution.insert(m_solution.end(),puzzlestring.begin(),puzzlestring.end());
	m_puzzle.clear();
	bmp.SaveToMemory("bmp",m_puzzle);

	return true;
}
예제 #5
0
int main () {
	hash_table hash_array;
	hash_table* hash_info = &hash_array;
	hash_info->size = 256;
	CreateHash(hash_info);
	struct timespec start, stop;
    	double worktime;

// test AddElement
	unsigned long j;
	char tmp[LENGTH] = {0};

	if (clock_gettime( CLOCK_REALTIME, &start) == -1) {
     		perror ("clock gettime");
		return -1;
     	}
   	
	for ( j = 0; j < 10000; ++j ) {
		AddElement(GenerateRandomString(tmp), hash_info);
	}

    	if (clock_gettime( CLOCK_REALTIME, &stop) == -1) {
      		perror ("clock gettime");
		return -1;
      	}

    	worktime = ((( stop.tv_sec - start.tv_sec )*1e9 + ( stop.tv_nsec - start.tv_nsec ))*1e-9)/10000;
    	printf ("%.10f sec for AddElement cycle \n", worktime);

// test SearchElement
	if (clock_gettime( CLOCK_REALTIME, &start) == -1) {
     		perror ("clock gettime");
		return -1;
     	}
   	
	for ( j = 0; j < 10000; ++j ) {
		SearchElement(GenerateRandomString(tmp), hash_info);
	}

    	if (clock_gettime( CLOCK_REALTIME, &stop) == -1) {
      		perror( "clock gettime" );
		return -1;
      	}

    	worktime = ((( stop.tv_sec - start.tv_sec )*1e9 + ( stop.tv_nsec - start.tv_nsec ))*1e-9)/10000;
    	printf("%.10f sec for SearchElement cycle \n", worktime);

// test Remove 
	if (clock_gettime( CLOCK_REALTIME, &start) == -1) {
     		perror( "clock gettime" );
		return -1;
     	}
   	int k;
	for ( j = 0; j < 10000; ++j ) {
		k = Remove(GenerateRandomString(tmp), hash_info);
	}

    	if (clock_gettime( CLOCK_REALTIME, &stop) == -1) {
      		perror( "clock gettime" );
		return -1;
      	}

    	worktime = ((( stop.tv_sec - start.tv_sec )*1e9 + ( stop.tv_nsec - start.tv_nsec ))*1e-9)/10000;
    	printf ("%.10f sec for Remove cycle \n", worktime);


// test CleanMemory 	
	if (clock_gettime( CLOCK_REALTIME, &start) == -1) {
     		perror ("clock gettime");
		return -1;
     	}
   	
	for ( j = 0; j < 10000; ++j ) {
		hash_table hash_array;
		hash_table* hash_info = &hash_array;
		hash_info->size = 256;
		CreateHash(hash_info);
		CleanMemory(hash_info);
	}
	
	if (clock_gettime( CLOCK_REALTIME, &stop) == -1) {
      		perror( "clock gettime" );
		return -1;
      	}

    	worktime = ((( stop.tv_sec - start.tv_sec )*1e9 + ( stop.tv_nsec - start.tv_nsec ))*1e-9)/10000;
    	printf ("%.10f sec for CreateHash and CleanMemory cycle\n", worktime);	


	return 0;
}