Changeset 08ed947 for tests/zombies/string-perf/make-corpus.cfa
- Timestamp:
- Feb 23, 2022, 6:13:02 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- afe9e45, c5af4f9
- Parents:
- cc7bbe6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/zombies/string-perf/make-corpus.cfa
rcc7bbe6 r08ed947 3 3 #include <limits.h> 4 4 #include <unistd.h> 5 #include <string.h> 6 7 // U(0,1) 8 static double U() { 9 return (double)rand() / (double)INT_MAX; 10 } 5 11 6 12 // generate random draws from a geometric distribution of the given mean … … 14 20 static int nextGeoRand() { 15 21 // ret = ⌊ln(U)/ln(1−p)⌋ where U ~ U(0, 1) 16 double U = (double)rand() / (double)INT_MAX; 17 return 1 + (int) (log(U) / denom); 22 return 1 + (int) (log(U()) / denom); 18 23 } 19 24 20 // write a randomly generated alphabetic string whose length is drawn fromabove distribution21 static void emit1( ) {22 int lim = nextGeoRand();25 // write a randomly generated alphabetic string whose length is adjused from a draw of the above distribution 26 static void emit1( int offset, double mcfreq, char mchar ) { 27 int lim = offset + nextGeoRand(); 23 28 // printf("==%d\n", lim); 24 29 for (i; lim) { 25 char emit = 'a' + (rand() % ('z'-'a')); 30 char emit; 31 if (U() < mcfreq) emit = mchar; 32 else emit = 'a' + (rand() % ('z'-'a')); 26 33 printf("%c", emit); 27 34 } … … 29 36 } 30 37 31 // usage: ./make-corpus toGen mean 38 // usage: ./make-corpus toGen mean [offset=0] [mcfreq=0.0] [mchar='-'] 39 // 40 // Outputs alphabetic (plus magic-char) strings, one per line. 41 // toGen: number of strings (lines) 42 // 43 // generated length ~ offset + geo(mean) 44 // >= 1 45 // 46 // offset=0, mean=1: constant length 1 47 // offset=0, mean=2: lengths go like number of coin tosses it takes to get heads 48 // offset=0, mean=6: lengths go like number of cube die rolls it takes to get ::: 49 // offset=15, mean=1: constant length 16 50 // offset=15, mean=2: population's minimum is 16 and mean is 17 51 // 52 // Magic Char (mc) does not affect these lengths. Any mc occurrence replaces an alphabetic char. 53 // mcfreq: (in [0,1]) expected fraction of the characters output that are mchar 54 // 32 55 int main(int argc, char ** argv) { 33 assert(argc == 3);34 56 35 int toGen = atoi(argv[1]); 36 assert(toGen > 0); 37 assert(toGen < 1000000); 57 int toGen; 58 int mean; 59 int offset = 0; 60 double mcfreq = 0.0; 61 char mchar = '-'; 38 62 39 int mean = atoi(argv[2]); 40 assert(mean > 0); 41 assert(mean < 1000); 63 assert(argc >= 3 && argc <= 6); 64 switch(argc) { 65 case 6: 66 assert(strlen(argv[5]) == 0); 67 mchar = argv[5][0]; 68 case 5: 69 mcfreq = atof(argv[4]); 70 assert(mcfreq >= 0.0 && mcfreq <= 1.0); 71 case 4: 72 offset = atoi(argv[3]); 73 assert(offset >= 0 && offset < 10000); 74 default: 75 mean = atoi(argv[2]); 76 assert(mean > 0); 77 assert(mean < 1000); 78 toGen = atoi(argv[1]); 79 assert(toGen > 0); 80 assert(toGen < 1000000); 81 } 42 82 43 83 initialize(mean); 44 84 for( i; toGen ) { 45 emit1( );85 emit1(offset, mcfreq, mchar); 46 86 } 47 87 }
Note: See TracChangeset
for help on using the changeset viewer.