Exemple #1
0
inline std::string rand_str(double avg_length, size_t seed) {
    std::poisson_distribution<size_t> dist(avg_length);
    static std::default_random_engine gen(seed);
    std::string s(dist(gen), 0);
    for (auto c = s.begin(); c != s.end(); ++c) { *c = rand_char('a', 'z', (seed*seed)^seed); }
    return s;
}
Exemple #2
0
static const char *gen_salt(void)
{
    static char salt[3];
    int i;

    for (i = 0; i < 2; i++)
        salt[i] = rand_char();
    salt[2] = '\0';

    return salt;
}
Exemple #3
0
char	*rand_str(int size)
{
  char *str, *cur;
  int num = 0;

  cur = str = malloc(size+1);
  while (num++ < size)
    *cur++ = rand_char();

  str[size]='\0';
  return str;
}
void fill_pattern(int size)
{
	int i;

	/*
	* Make sure that anything in the buffer past size is zero'd,
	* as a regular file should look.
	*/
	memset(pattern, 0, PATTERN_SZ);
	for (i = 0; i < size; i++)
		pattern[i] = rand_char();
}
unsigned int get_rand_nam(char *str, unsigned int least, unsigned most)
{
	unsigned nam_len = get_rand(least, most);
	unsigned i = 0;

	memset(str, 0, OCFS2_MAX_FILENAME_LEN);

	while (i < nam_len) {
		str[i] = rand_char();
		i++;
	}

	str[nam_len] = '\0';
	return nam_len;
}
Exemple #6
0
int main(int argc, char** argv) {
    size_t i, candidate_score, generation, tlen = strlen(target);
    char candidate[tlen + 1];

    rand_seed = rand_seed ? rand_seed : time(NULL);
    srand(rand_seed);

    for(i = 0; i < tlen; ++i) {
        candidate[i] = rand_char();
    }
    candidate_score = score(candidate);

    printf("target: '%s'\n", target);
    printf("pool: '%s'\n", pool);
    printf("population size: %d\n", generation_size);
    printf("mutation rate: %d/100\n", mutation_rate);
    printf("random seed: %d\n", rand_seed);
    printf("------------------------------------------------\n");
    printf("%zd: '%s' (%zd)\n", 1, candidate, candidate_score);
    for(generation = 2; candidate_score != tlen; ++generation) {
        char base[tlen + 1];
        strcpy(base, candidate);
        candidate_score = 0;
        for(i = 1; i <= generation_size; ++i) {
            char child[tlen + 1];
            size_t child_score;
            strcpy(child, base);
            mutate(child);
            child_score = score(child);
            if(verbose) {
                printf("    child %zd: '%s' (%zd)\n", i, child, child_score);
            }
            if(child_score >= candidate_score) {
                strcpy(candidate, child);
                candidate_score = child_score;
            }
        }
        printf("%zd: '%s' (%zd)\n", generation, candidate, candidate_score);
    }

    return 0;
}
Exemple #7
0
int test_sys_rand(void)
{
	char str[64];
	uint8_t buf[64];

	volatile uint16_t u16 = rand_u16();
	volatile uint32_t u32 = rand_u32();
	volatile uint64_t u64 = rand_u64();
	volatile char ch      = rand_char();

	(void)u16;
	(void)u32;
	(void)u64;
	(void)ch;

	rand_str(str, sizeof(str));
	rand_bytes(buf, sizeof(buf));

	return 0;
}
int main()
{
  srand(0);
  int T,N,H,i,j,score;
  scanf("%d%d%d",&T,&N,&H);
  while(T--){
    for(i=0;i<N;i++){
      int len = rand()%5 + 8;
      char pass[13];
      for(j = 0; j < len; j++){
	pass[j] = rand_char();
      }
      pass[j] = '\0';
      printf("%s\n",pass);
      fflush(stdout);
    }
    scanf("%d",&score);
    srand(rand());
  }
  return 0;
}
Exemple #9
0
void mutate(char *string) {
    for(; *string; ++string) {
        if(rand() % 100 < mutation_rate) { *string = rand_char(); }
    }
}