Пример #1
0
int main(int argc, char **argv)
{
    srand(time(NULL));
    if(argc<3)
        return -1;
    int len = atoi(argv[1]);
    int count = atoi(argv[2]);
    for (int i=0; i < count; ++i) {
        std::cout << randomStr(len) << std::endl;
    }
    return 0;
}
Пример #2
0
static int mkTempDir(char *dir)
{
    int i, l = strlen(dir) - 6;

    for (i = 0; i < 100; i++) {
        randomStr(dir + l);
        if (!mkdir(dir, 0700))
            return True;
        if (errno != EEXIST)
            break;
    }
    return False;
}
std::string RandomizedScalarGenerator::_generateRandomString() const {
    const std::size_t kMaxStrLength = 500;
    const StringData kViableChars =
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        "abcdefghijklmnopqrstuvwxyz"
        "0123456789"
        "$.\0"_sd;
    std::size_t randomStrLength = this->_random.nextInt32(kMaxStrLength);
    std::string randomStr(randomStrLength, '\0');
    for (std::size_t i = 0; i < randomStrLength; i++) {
        randomStr[i] = kViableChars[this->_random.nextInt32(kViableChars.size())];
    }

    return randomStr;
}
Пример #4
0
Файл: ec.c Проект: kev40293/ida
int getSendLocations(int minimum, int chunksize, struct comLocations * loc){
	// This functions fill the comLocations structure that contains future chunk locations.
	
	
	int blocksNumber = loc->locationsNumber; //blocksNumber is the number of actual data blocks available
	int i;
	
	char chunkname[CHUNKNAME_LENGTH];
	unsigned int chunknameLen = CHUNKNAME_LENGTH;
	//1. We acquire the locations in ZHT
	ZHTgetLocations(zhtClient, loc);
	
	struct comTransfer * current = loc->transfers;
	int LocationsNumber = loc->locationsNumber;

	if(LocationsNumber < minimum){
		return 1; //That should be defined as a constant: NOTENOUGHLOCATIONS
	}
	
	blocksNumber = LocationsNumber; //The blocksNumber is maxed by the available Locations number

	//2. We have the destination nodes, we need to attribute blocks to them.
	//2.1 RandomFilename
	char filehash[64];
	randomStr(filehash,64);
		
	
	for (i = 0; i < blocksNumber; i++) {	
		
		chunknameLen = sprintf(chunkname, "%s.%d", filehash, i);
		current->distantChunkName = (char *) malloc(chunknameLen+1);
		strcpy(current->distantChunkName,chunkname);
		
		current->chunkNumber = i;
		
		current = current->next;
	}
	
	loc->locationsNumber = blocksNumber; // We actually tell the program how many blocks we can transfer
	
	return 0;

}