Ejemplo n.º 1
0
//___________________________________________________________________________________________
Bool_t KVIntegerList::Remove(Int_t val, Int_t freq)
{
//On retire "freq" fois la valeur val
//la methode retourne kTRUE si cette valeur etait effectivement presente, kFALSE sinon
//Si freq > la frequence initiale ( KVIntegerList::GetFrequency(Int_t ) )de la valeur, on la retire complétement
//
   return remove_values(val, freq);

}
Ejemplo n.º 2
0
/* randomly swap out values, by num_itr,
 * number of iterations, of known solved puzzle;
 * should result in a new (completed) random puzzle
 */
static int build_puzzle(int* puzzle, int* matrix)
{
    int num_itr = 0, x = 0, y = 0;
    puts("generating sudoku puzzle ...");

	/* There is a stdlib call "rand"; this function is tuned primarily for speed
	 * and distribution, not for unpredictability. Almost all built-in random 
	 * functions for various languages and frameworks use this function by 
	 * default. There are also "cryptographic" random number generators that are
	 * much less predictable, but run much slower. These should be used in any sort
	 * of security-related application. - tylerl
	 * http://stackoverflow.com/questions/822323/how-to-generate-a-random-number-in-c
	 */

#ifdef JSW_RANDOM
    puts("using jsw_srand()");
    jsw_seed(time(NULL));
    num_itr = (jsw_rand() % 1000000);
#else
    puts("using srand()");
    srand(time(NULL));
    num_itr = (rand() % 1000000);
#endif
    
    printf("number iterations: %d\n", num_itr);

    for (int i = 0; i<num_itr; i++) 
    {
#ifdef JSW_RANDOM
        x = (jsw_rand() % 9);
        y = (jsw_rand() % 9);
#else
        x = (rand() % 9);
        y = (rand() % 9);
#endif
        x++;
        y++;
        /* printf("x = %d, y = %d\n", x, y); */
        swap_numbers(puzzle, x, y);
    }

    print_grid(puzzle_solution);
    remove_values(matrix);
    return 0;
}