/************************************************************************ * Routines to download random seed value from www.random.org * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * ************************************************************************ ************************************************************************ * Writen by: * * Laszlo BALOGH * * e-mail: blaci947@yahoo.co.uk * * Ph.D. student @ Dep. of Theor. Phys., BUTE, Budapest, Hungary * * 2011. * ************************************************************************/ #include #include #include #include "downloadseed.h" int DownloadSeed(unsigned long int *seed_, unsigned long int *warmup_) // seed + warm up // download integers (3 x 16 bits) from http://www.random.org // * it OWERWRITES the "random.org.txt" file, // * it will USE THE WGET software, // * it will CONNECT TO THE INTERNET // return value: 1, if no error occured, // zero, if an error occured (cannot open "random.org" file, // the wget is not installed, // the random.org server is unavailable, // or the free quota is exceeded) // To check your free quota, visit: http://www.random.org/quota/ // or type: wget -O /dev/stdout -q "http://www.random.org/quota/?format=plain" { unsigned long int a,b,c; int sys; char cmd[]="wget \"http://www.random.org/integers/?num=3&min=0&max=65535&col=5&base=10&format=plain&rnd=new\" -O random.org.txt -q -T 3"; FILE* rnd = NULL; //open (and erase) "random.org.txt" file rnd = fopen("random.org.txt", "wt"); if (!rnd) { fprintf(stderr, "Cannot open \"random.org.txt\" for writing\n"); return 0; } fclose(rnd); // downloading 3 x 16 bits of integer into "random.org" sys = system(cmd); if (sys) { fprintf(stderr, "An error accoured while downloading random numbers from http://www.random.org. Please check:\n"); fprintf(stderr, " * is wget installed?\n"); fprintf(stderr, " * can you access the http://www.random.org website?\n"); fprintf(stderr, " * is not your free download quota exceeded?\n"); return 0; } //open (and read) "random.org.txt" file rnd = fopen("random.org.txt", "rt"); if (!rnd) { fprintf(stderr, "Cannot open \"random.org.txt\" for reading\n"); return 0; } if (fscanf(rnd, "%lu %lu %lu", &a, &b, &c) != 3) { fprintf(stderr, "Wrong format in \"random.org.txt\" file\n"); fclose(rnd); return 0; } fclose(rnd); *seed_ = (a << 16) | b; *warmup_ = 65535 + c; return 1; } int RNGSeedWarmupGiven(gsl_rng* rng_, const unsigned long int s_, const unsigned long int w_) // * initializes the Randon Number Generator with the given value // * gets some the given amount of random numbers - "warming up" the generator { unsigned long int i; gsl_rng_set(rng_, s_); for (i=0; i