Ejemplo n.º 1
0
int get_new_powball(int *pow_ball) 
{
	int new_pwr_nms[76] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10,  11, 12, 13, 14, 15,
		16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
		33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
		50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
		67, 68, 69, 70, 71, 72, 73, 74, 75, 0};

	int i, rand_pos, iter=1;

	rand_pos = get_rand_num(MEGAMIL)-1;

	for (i = 0; i < 5; i++) 
	{
		new_pwr_nms[rand_pos] = 0;

		rand_pos = get_rand_num(MEGAMIL)-1;  //get_randpos(MD, iter++, MEGAMIL);

		while (new_pwr_nms[rand_pos] == 0)
		{
		    
        	rand_pos = get_rand_num(MEGAMIL)-1;  //pos(MD, iter++, MEGAMIL);

		}

        pow_ball[i] = new_pwr_nms[rand_pos];
	}

	return 0;

}
Ejemplo n.º 2
0
Archivo: bingo.c Proyecto: codeblock/C
int get_rand_num(int elem) {
	int i, j;
	int limit;
	int is;
	int n;
	
	limit = elem * elem; // 25 = 5 * 5;
	is = 0;
	n = rand() % limit + 1; // 1 ~ 25
	
	for (i = 0; i < elem; i++) {
		for (j = 0; j < elem; j++) {
			if (bingo[i][j] == n) {
				is = 1;
				break;
			}
		}
		if (is == 1) {
			break;
		}
	}
	
	if (is == 1) {
		return get_rand_num(elem);
	}
	
	return n;
}
Ejemplo n.º 3
0
int get_new_powball(int *pow_ball) 
{
	int new_pwr_nms[76] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10,  11, 12, 13, 14, 15,
		16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
		33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
		50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
		67, 68, 69, 70, 71, 72, 73, 74, 75, 0};

	int i, rand_pos, packed_count = 0;
        uint64_t v[8];
  
	get_rand_num(v);
    
        rand_pos = v[packed_count++] % MEGAMIL;
	for (i = 0; i < 5; i++) 
	{
		pow_ball[i] = new_pwr_nms[rand_pos];
		new_pwr_nms[rand_pos] = 0;

		rand_pos = v[packed_count++] % MEGAMIL;  //get_randpos(MD, iter++, MEGAMIL);
	        
		while (new_pwr_nms[rand_pos] == 0)
		{
		     if (packed_count < 8)	
		          rand_pos = v[packed_count++] % MEGAMIL;  //pos(MD, iter++, MEGAMIL);
		     else
		     {
			get_rand_num(v);
			packed_count = 0;
			rand_pos = v[packed_count++] % MEGAMIL;
		     }
		   
		}
	}

        if (packed_count < 7)
	   return  v[packed_count + 1];
        else
        {  
	    get_rand_num(v);
	    packed_count = 0;
	    return  v[packed_count + 1];
	}
    
        return 0;

}
Ejemplo n.º 4
0
Archivo: bingo.c Proyecto: codeblock/C
void bingo_init(int elem) {
	int i, j;
	
	for (i = 0; i < elem; i++) {
		for (j = 0; j < elem; j++) {
			bingo[i][j] = get_rand_num(elem);
		}
	}
}
Ejemplo n.º 5
0
int main(void)
{
	int num_arr[SIZE];

	get_rand_num(num_arr, SIZE);
	puts("\nInitial array:");
	print(num_arr, SIZE);
	sort_num_arr(num_arr, SIZE);
	puts("Sorted array:");
	print(num_arr, SIZE);

	return 0;
}
Ejemplo n.º 6
0
/*
 * create_mole()
 * create mole process located at ${HOME}
 */
static pid_t create_mole(void) {
    pid_t pid = 0;
    char *arglist[2];
    char mole_path[PATH_MAX];

    snprintf(mole_path, sizeof(mole_path), "%s/mole", getenv("HOME"));

    /*
     * check if mole is exist and exec-able
     */
    if (access(mole_path, X_OK) != 0) {
        return pid;
    }

    /*
     * create mole process randomly
     */
    if (get_rand_num() % 2) {
        arglist[0] = "mole1";
    } else {
        arglist[0] = "mole2";
    }
    arglist[1] = NULL;

    if ((pid = fork()) < 0) {
        return pid;
    }

    if (pid == 0) { /* child process */
        if (execv(mole_path, arglist) < 0) {
            exit(1);
        }
    }

    return pid;
}
Ejemplo n.º 7
0
int main(int argc, char **argv) 
{
	int i, pow_ball[6] = {0}, j, sum = 0;
	unsigned long long rand_pos;
	int new_pwr_nms[10] = { 0 };
	int new_firstdigi = 0, last_firstdigi = 0, repeat[60] = { 0 };
	int sum_of_pwball = 0, first_pwball_array[10], index = 0, index_nst = 0,
		sum_of_repeats[10] = { 0 };
	double repeat_sums_avg[10] = { 0.0 };

	j = i = 0;

	if (argc < 2)
		exit(-1);

	//quick_sort(pow_ball, 0, 4);
	while (j < atoi(argv[1])) 
	{
		get_new_powball(pow_ball);
		quick_sort(pow_ball, 0, 4);

		for (i = 0; i < 5; i++) {
			if (i != 4)
				sum += (pow_ball[i + 1] - pow_ball[i]);
		}

		for (i = 0; i < 5; i++)
				printf("%2i ", pow_ball[i]);

		printf("  %2i    %2i\n", get_rand_num(15), sum);
		//printf("  %2i \n", get_rand_num(15));
		sum = 0;
		j++;
	}

	/* 
	* 
	*/

	/*   new_firstdigi = pow_ball[0];
	if (new_firstdigi == last_firstdigi)
	{
	printf("R: %i, I: %i\n", new_firstdigi, j);

	}
	*/
	/*

	}

	quick_sort(sum_of_repeats, 0, 4);
	for (i = 0; i < 5; i++)
	{
	repeat_sums_avg[i] = sum_of_repeats[i] + repeat_sums_avg[i];
	//printf("%i  %i\n", repeat_sums_avg[i], sum_of_repeats[i]), 
	sum_of_repeats[i] = 0;
	}
	index++;

	}



	for (i = 0; i < 5; i++)
	printf("%i  %f\n", i + 1, repeat_sums_avg[i] / (index));

	*/

	return 0;
}