예제 #1
0
/**
  * the main function. needs at least 1 arg.
  * 
  * inputs:
  *	[0] the program name
  *	[1] the filename to export to
  *	[2] the number of inputs to generate
  *	[3] should the keys be ordered?
  *	[4] ascending or descending?
  */
int main(int argc, char** argv) {
    char    *filename;
    int	    n		= 25;
    int	    ordered	= 0;
    int	    asc		= 1;
    switch(argc) {
	case 5:
	    asc		= atoi(argv[4]);
	    // fallthrough
        case 4:
	    ordered	= atoi(argv[3]);
	    // fallthrough
	case 3:
	    n		= atoi(argv[2]);
	    // fallthrough
	case 2:
	    filename	= argv[1];
	    break;
	// if we're not given the right number of args
	default:
	    printf("Incorrect number of arguments!\n");
	    exit(0);
	    break;
    }

    // initialize the original array
    char *str = smalloc((MAX_STR + 1) * sizeof(char));
    if(ordered) {
	for(int i = 0; i < MAX_STR; i++)
	    str[i] = asc ? FRST_CHR : LAST_CHR;
    } else {
	next_rnd(str);
    }

    // write the required inputs to file
    FILE *fp = fopen(filename, "w");
    for(int i = 0; i < n; i++) {
	// print the current string
	fprintf(fp, "%s\n", str);
	// get the next string
	if(ordered) {
	    if(asc) {
		next_ord(str);
	    } else {
		prev_ord(str);
	    }
	} else {
	    next_rnd(str);
	}
    }
    fclose(fp);

    // return success
    return 0;
}
예제 #2
0
void rnd_init(struct rnd *rnd, unsigned long seed)
{
	int i;
	uint64_t x = seed*Z1 + seed*Z2 + Z5 + Z1;
	x = (MASK(x) != 0) ? x : (Z5 + Z2);
	rnd->s1 = MASK(x);
	x = x*Z1 + x*Z2 + Z2;
	x = (MASK(x) != 0) ? x : (Z5 + Z1);
	rnd->s2 = MASK(x);
	for (i=0; i<11; i++)
		next_rnd(rnd);
}
예제 #3
0
double rnd_open(struct rnd *rnd)
{
	/* Return double (0,1) in continuous uniform distribution */
	return OPEN(next_rnd(rnd));
}
예제 #4
0
double rnd_closed(struct rnd *rnd)
{
	/* Return double [0,1] in continuous uniform distribution */
	return CLOSED(next_rnd(rnd));
}
예제 #5
0
uint64_t rnd_u64(struct rnd *rnd)
{
	return next_rnd(rnd);
}
예제 #6
0
uint32_t rnd_u32(struct rnd *rnd)
{
	return H32(next_rnd(rnd));
}