diff -urp ksudoku-0.3/src/glwindow.cpp ksudoku-0.3.safari/src/glwindow.cpp --- ksudoku-0.3/src/glwindow.cpp 2005-09-29 18:16:04.000000000 +0300 +++ ksudoku-0.3.safari/src/glwindow.cpp 2007-03-09 05:02:56.981346466 +0200 @@ -36,7 +36,6 @@ glWindow::glWindow(QWidget *parent, cons order = orderp; base = (int) sqrt(order); size = base*order; - std::srand( time(0) ); if(order == 9) mySolver = solver3d09; else if(order == 16) mySolver = solver3d16; diff -urp ksudoku-0.3/src/ksudokuview.cpp ksudoku-0.3.safari/src/ksudokuview.cpp --- ksudoku-0.3/src/ksudokuview.cpp 2005-09-29 18:15:47.000000000 +0300 +++ ksudoku-0.3.safari/src/ksudokuview.cpp 2007-03-09 05:08:57.981720495 +0200 @@ -32,7 +32,6 @@ ksudokuView::ksudokuView(QWidget *parent void ksudokuView::setup(int order, int difficulty, int s, bool dub) { - std::srand( time(0) );//srandom((unsigned)time( NULL ) ); puzzle_mark_wrong=true; btns = 0; current_selected_number = 0; @@ -125,7 +124,6 @@ int ksudokuView::genPuzzle(int difficult { ((ksudoku*)parent())->t.start(); - std::srand( time(0) ); if(dub==false) { mySolver->solve(puzzle, 1, puzzle); diff -urp ksudoku-0.3/src/main.cpp ksudoku-0.3.safari/src/main.cpp --- ksudoku-0.3/src/main.cpp 2005-09-28 19:10:34.000000000 +0300 +++ ksudoku-0.3.safari/src/main.cpp 2007-03-09 05:17:37.509232645 +0200 @@ -28,6 +32,79 @@ skSolver* solver3d09 = new skSolver(9 , skSolver* solver3d16 = new skSolver(16, true); skSolver* solver3d25 = new skSolver(25, true); +#define R(a,b) (((a) << (b)) | ((a) >> (32 - (b)))) +static void salsa20(uint32_t out[16],uint32_t in[16]) +{ + int i; + uint32_t x[16]; + + for (i = 0; i < 16; ++i) x[i] = in[i]; + + for (i = 20;i > 0;i -= 2) { + x[ 4] ^= R(x[ 0]+x[12], 7); + x[ 8] ^= R(x[ 4]+x[ 0], 9); + x[12] ^= R(x[ 8]+x[ 4],13); + x[ 0] ^= R(x[12]+x[ 8],18); + x[ 9] ^= R(x[ 5]+x[ 1], 7); + x[13] ^= R(x[ 9]+x[ 5], 9); + x[ 1] ^= R(x[13]+x[ 9],13); + x[ 5] ^= R(x[ 1]+x[13],18); + x[14] ^= R(x[10]+x[ 6], 7); + x[ 2] ^= R(x[14]+x[10], 9); + x[ 6] ^= R(x[ 2]+x[14],13); + x[10] ^= R(x[ 6]+x[ 2],18); + x[ 3] ^= R(x[15]+x[11], 7); + x[ 7] ^= R(x[ 3]+x[15], 9); + x[11] ^= R(x[ 7]+x[ 3],13); + x[15] ^= R(x[11]+x[ 7],18); + x[ 1] ^= R(x[ 0]+x[ 3], 7); + x[ 2] ^= R(x[ 1]+x[ 0], 9); + x[ 3] ^= R(x[ 2]+x[ 1],13); + x[ 0] ^= R(x[ 3]+x[ 2],18); + x[ 6] ^= R(x[ 5]+x[ 4], 7); + x[ 7] ^= R(x[ 6]+x[ 5], 9); + x[ 4] ^= R(x[ 7]+x[ 6],13); + x[ 5] ^= R(x[ 4]+x[ 7],18); + x[11] ^= R(x[10]+x[ 9], 7); + x[ 8] ^= R(x[11]+x[10], 9); + x[ 9] ^= R(x[ 8]+x[11],13); + x[10] ^= R(x[ 9]+x[ 8],18); + x[12] ^= R(x[15]+x[14], 7); + x[13] ^= R(x[12]+x[15], 9); + x[14] ^= R(x[13]+x[12],13); + x[15] ^= R(x[14]+x[13],18); + } + for (i = 0;i < 16;++i) out[i] = x[i] + in[i]; +} + +static uint32_t salsa20_in[16]; +static uint32_t salsa20_out[16]; +static uint32_t nrints; +static int salsa20_init; + +uint32_t RANDOM(uint32_t max) +{ + if (!salsa20_init) { + FILE *fd; + + salsa20_init = 1; + fd = fopen("/dev/urandom", "rb"); + if (fd == NULL) _exit(1); + if (fread(salsa20_in, sizeof(salsa20_in), 1, fd) != 1) _exit(1); + fclose(fd); + } + + if (nrints == 0) { + if (!++salsa20_in[0]) if (!++salsa20_in[1]) if (!++salsa20_in[2]) if (!++salsa20_in[3]) + if (!++salsa20_in[4]) if (!++salsa20_in[5]) if (!++salsa20_in[6]) if (!++salsa20_in[7]) + if (!++salsa20_in[8]) if (!++salsa20_in[9]) if (!++salsa20_in[10]) if (!++salsa20_in[11]) + if (!++salsa20_in[12]) if (!++salsa20_in[13]) if (!++salsa20_in[14]) ++salsa20_in[15]; + nrints = 16; + salsa20(salsa20_out, salsa20_in); + } + return (salsa20_out[--nrints]) % max; +} + int main(int argc, char **argv) { solver09->init(); diff -urp ksudoku-0.3/src/sudoku_solver.cpp ksudoku-0.3.safari/src/sudoku_solver.cpp --- ksudoku-0.3/src/sudoku_solver.cpp 2005-09-29 19:08:11.000000000 +0300 +++ ksudoku-0.3.safari/src/sudoku_solver.cpp 2007-03-09 05:03:59.273650131 +0200 @@ -77,7 +77,6 @@ int get_simmetric(int order, int size, i int skSolver::remove_numbers(skPuzzle* p, int level, int simmetry, int type) { - std::srand(time(0)); int b; int cnt=p->size; int to=p->size*(4+4*(level==-1)); diff -urp ksudoku-0.3/src/sudoku_solver.h ksudoku-0.3.safari/src/sudoku_solver.h --- ksudoku-0.3/src/sudoku_solver.h 2005-09-28 21:41:23.000000000 +0300 +++ ksudoku-0.3.safari/src/sudoku_solver.h 2007-03-09 05:13:12.203716446 +0200 @@ -4,7 +4,6 @@ #define ITERATE(i,s) for(int ((i))=0; ((i))<((s)); ((i))++) -#define RANDOM(x) (int) (x*((float)rand())/(RAND_MAX+1.0f)) //j=1+(int) (10.0*rand()/(RAND_MAX+1.0)); //#define RANDOM(x) std::rand() % ((x)) #define SUDOKU_HARDEST -1 @@ -24,6 +23,7 @@ #include #include +#include /** @author Francesco Rossi @@ -129,5 +129,8 @@ extern skSolver* solver25; extern skSolver* solver3d09; extern skSolver* solver3d16; extern skSolver* solver3d25; + +extern uint32_t RANDOM(uint32_t); + #endif