int hgt_genome_mutate_(hgt_genome *g, unsigned int pos, unsigned char_max, const gsl_rng *r) { char random_c = random_char(r); while (random_c == g->seq[pos] ) { random_c = random_char(r); } g->seq[pos] = random_c; return EXIT_SUCCESS; }
static char * generate_random_name (const char *filename) { char *ret, *p; size_t i; ret = malloc (strlen (filename) + 16); if (!ret) { perror ("malloc"); exit (EXIT_FAILURE); } strcpy (ret, filename); p = strrchr (ret, '/'); assert (p); p++; /* Because of "+ 16" above, there should be enough space in the * output buffer to write 8 random characters here. */ for (i = 0; i < 8; ++i) *p++ = random_char (); *p++ = '\0'; return ret; /* caller will free */ }
char * random_key (const unsigned int keylen){ char * key = calloc(keylen+1,sizeof(char)); for ( int i=0 ; i<keylen ; i++){ key[i] = random_char(); } return key; }
main(int argc, char **argv) { char *start = sbrk(0); int i, j; int repetition = 100; if (argc >= 2) { repetition = atoi(argv[1]); } if (start != (char*)(((long)start/SIZE+1)*SIZE)) { /* align to the page boundary */ sbrk((char*)(((long)start/SIZE+1)*SIZE) - start); start = sbrk(0); } printf("brk start %d repetition\n_end = %lx, sbrk ptr=%lx\n", repetition, &_end, start); for (j = 0; j < repetition; j++) { char *x; write(1, ".", 1); /* Allocate the pages */ for (i = 0; i < 50; i++) { char *s; int i; s = x = sbrk(SIZE); /* See if the region is all 0. */ /* XXX this doesn't hold on OSF */ for (i = 0; i < SIZE; i++) { if (*s != 0) { printf("sbrk'ed memory not 0 at %lx", s); exit(1); } *s = random_char(); s++; } } /* Deallocate the pages */ for (i = 0; i < 50; i++) { x = sbrk(-SIZE); } if (x != start + SIZE) { printf("???? x(%lx) != start(%lx)\n", x, start); exit(1); } } printf("\nok.\n"); exit(0); }
char * hgt_genome_random_sequence(int length, const gsl_rng *r) { char * seq = (char *) malloc((length+1) * sizeof(char)); int i; for (i = 0; i < length; i++) { seq[i] = random_char(r); } seq[length] = '\0'; return seq; }
int test2() { char c; c = random_char(); return ( ft_strchr(test_string, c) == strchr(test_string, c) ); }
void draw_cells(cellgrid *cgrid) { int x,y; erase(); //clearok(stdscr,TRUE); for(y=0;y<=cgrid->max_y;y++){ for(x=0;x<=cgrid->max_x;x++){ if(get_cell(cgrid,x,y)==TRUE){ #ifndef RANDOMCHAR mvaddch(x,y,livecellchar); #else mvaddch(x,y,random_char()|A_BOLD); #endif } } } sprintf(status,"Iteration: %lu\t\tLive cells: %u",cgrid->iteration,cgrid->live_cells); mvaddstr(LINES-1,0,status); refresh(); //microsleep(100); }
static void test_pushchars (extstring_t* str, int numchars) { char *s1, *s2; int i; bebop_log (1, "test_pushchars: starting tests\n"); assert (numchars >= 0); s2 = bebop_malloc ((numchars + 1) * sizeof (char)); extstring_clear (str); for (i = 0; i < numchars; i++) { char c = random_char (); extstring_pushchar (str, c); s2[i] = c; } s2[numchars] = '\0'; /* Now compare the extstring with s2 */ s1 = extstring_string (str); if (s1 == NULL) { bebop_error ("test:extstring:pushchars", "extstring_string() returned NULL unexpectedly"); bebop_exit (EXIT_FAILURE); } bebop_log (2, "String 1: %s\n", s1); bebop_log (2, "String 2: %s\n", s2); if (0 != strcmp (s1, s2)) { bebop_error ("test:extstring:pushchars", "s1 and s2 are not equal"); bebop_exit (EXIT_FAILURE); } bebop_free (s2); bebop_log (1, "test_pushchars: passed all tests\n"); }
void test_random_char() { int test_char = random_char(); ok1(test_char >= CHAR_MIN && test_char <= CHAR_MAX); }