示例#1
0
int E() {
	if (randInt(10) < 5) {
		T(); printf("%c", randChar("+-*/")); E();
	} else {
		T();
	}
}
示例#2
0
int T() {
	if (randInt(10) < 7) {
		printf("%c", randChar("0123456789"));
	} else {
		printf("("); E(); printf(")");
	}
}
示例#3
0
String RandomUtils::randString(int length)
{
    String ret;
    for(auto i = 0; i < length; ++i)
        ret.push_back(randChar());
    return ret;
}
示例#4
0
文件: utils.cpp 项目: AlphaBeth/ITMO
char *randStr(int size) {
    char *res = (char *) malloc(size);
    for (int i = 0; i < size; i++) {
        res[i] = randChar('0', 'z');
    }
    res[size - 1] = '\0';
    return res;
}
示例#5
0
int main(int argc,const char *argv[]){

	
	// set seed for random number generator
	unsigned int seed = (unsigned int)time(NULL);
	srand(seed);
	//printf("%d\n",seed);
	
	
	// what is the starting string
	char target[]="Target string";
	length = (int)strlen(target);  // use length of string function, cast it as an int because otherwise it's an unsigned int
		//strlen doesn't include the /0 in the length of the string
	
	//make a random starting sequence of letters
	char *startString = malloc((length+1)*sizeof(char));  /// BECAUSE strlen doesn't include the /0 in the length of the string
	int i;
	for(i=0; i < length; i++){
		startString[i]= randChar();
	}
	startString[length]='\0'; /// BECAUSE the array starts with a zero and goes to length (rather than length-1) then we just put the null character in there
	
	int muts = 0; //how many mutations happen to get to the target sequence
	int mutationsAtMismatches;
	
	while(stringEval(startString, target)>0){  // evolve the string of characters
		//mutate
		int site;
		do{
			site = rand_between(length);
			muts++;
		}while(startString[site]==target[site]);
		
		startString[site]=randChar();
		//evaluate how close the two strings are -- Hamming distance ( sum over units for if 1 when units are different and 0 if same )
			//--inherent in the loop
		//decide --inherent in the loop
		//stop when we get the phrase we want--inherent in the loop
		mutationsAtMismatches++;
		printf("%s \n", startString); //Print mutations to console as they happen
	}
	
printf("Number of mutations to target= %d \n", mutationsAtMismatches); //print the number of steps it takes to get to the target sequence
	
	
}
示例#6
0
文件: testme.c 项目: Jmmyr41/cs362f15
char inputChar() {
  // TODO: rewrite this function

  char cs[] = "[](){}ax ";
  size_t n = sizeof(cs) / sizeof(cs[0]);

  return randChar(cs, n - 1);
}
示例#7
0
std::string randPalindrome(const int len, const int& correct) {
  std::string front = "", back = "";
  for (int i = 0; i < len >> 1; ++i) {
    const char s = randChar();
    front += s;
    back += i == correct ? ((s + 1 - 'a') % 26) + 'a' : s;
  }
  std::reverse(back.begin(), back.end());
  return front + back;
}
示例#8
0
文件: testme.c 项目: Jmmyr41/cs362f15
char *inputString() {
  static char s[MAX_INPUT_STRING];
  char x[] = "reset";
  size_t n = sizeof(x) / sizeof(x[0]);
  size_t i;
  int len = randRange(MIN_INPUT_STRING, MAX_INPUT_STRING);

  for (i = 0; i < len; i++) {
    s[i] = randChar(x, n);
  }

  return s;
}
示例#9
0
/* Test sur le retour du caractère tiré aléatoirement */
void testRandChar(void) {
    CU_ASSERT(islower(randChar()));
    CU_ASSERT(!isalpha(randChar()));
    CU_ASSERT(isupper(randChar()));
}
示例#10
0
static void createGUID(char * guid)
{
    srand((unsigned int)time(0));

    guid[0]     = randChar();
    guid[1]     = randChar();
    guid[2]     = randChar();
    guid[3]     = randChar();
    guid[4]     = randChar();
    guid[5]     = randChar();
    guid[6]     = randChar();
    guid[7]     = randChar();
    guid[8]     = '-';
    guid[9]     = randChar();
    guid[10]    = randChar();
    guid[11]    = randChar();
    guid[12]    = randChar();
    guid[13]    = '-';
    guid[14]    = randChar();
    guid[15]    = randChar();
    guid[16]    = randChar();
    guid[17]    = randChar();
    guid[18]    = '-';
    guid[19]    = randChar();
    guid[20]    = randChar();
    guid[21]    = randChar();
    guid[22]    = randChar();
    guid[23]    = '-';
    guid[24]    = randChar();
    guid[25]    = randChar();
    guid[26]    = randChar();
    guid[27]    = randChar();
    guid[28]    = randChar();
    guid[29]    = randChar();
    guid[30]    = randChar();
    guid[31]    = randChar();
    guid[32]    = randChar();
    guid[33]    = randChar();
    guid[34]    = randChar();
    guid[35]    = randChar();
    guid[36]    = 0;

}
示例#11
0
文件: gint.c 项目: cccnqu1/cccwd
int N() {
	printf("%c", randChar("0123456789")); 
	if (randInt(10) < 8)
		N();
}