Re: Faster source of random numbers for blanking harddrives
On Thu, Oct 25, 2007 at 02:19:59PM +0800, Bob wrote:
> if you type
> dd if=/dev/urandom of=/dev/null count=100000
> 100000+0 records in
> 100000+0 records out
> 51200000 bytes (51 MB) copied, 14.0076 seconds, 3.7 MB/s
>
> whereas
> dd if=/dev/zero of=/dev/null count=100000
> 100000+0 records in
> 100000+0 records out
> 51200000 bytes (51 MB) copied, 0.0932449 seconds, 549 MB/s
>
> Is there a faster source or random or pseudo-random numbers because at
> 4MB/s it'll take a loooong time to blank a 60GB drive let alone a 500GB job?
Most scientific libraries have fast, high-quality random number
generators. If you have libgsl0-dev installed, compile the attached
program with
$ make gsl_rng_info CFLAGS+="-lm -lgsl -lcblas -O6"
I get about 150 MB/s with the generator gfsr4:
$ time GSL_RNG_TYPE=gfsr4 ./gsl_random_spew spew | head -c 500m > /dev/null
GSL_RNG_TYPE=gfsr4
generator type: gfsr4
seed = 0
first value = 2901276280
real 0m3.467s
user 0m2.612s
sys 0m0.672s
My computer has a different bus speed from yours, etc., so experiment.
I don't know whether this generator fills all 32 bits of each
generated number, or its period; those are in the GSL info manual
(from which I cribbed most of this program). If you care about those
sorts of details, you might follow another poster's advice and
consider an existing solution.
Nota bene: don't call this program without redirecting stdout :)
Rob
--
Rob Mahurin
Dept. of Physics & Astronomy
University of Tennessee phone: 865 207 2594
Knoxville, TN 37996 email: rob@utk.edu
#include <stdio.h>
#include <gsl/gsl_rng.h>
gsl_rng * r; /* global generator */
#define CHUNKSIZE (1024*1024)
/*
* Calling this program with any arguments will spew infinite amounts
* of binary data to your terminal. Caveat emptor.
*/
int main (int argc, char* argv[])
{
const gsl_rng_type * T;
gsl_rng_env_setup();
T = gsl_rng_default;
r = gsl_rng_alloc (T);
fprintf (stderr,"generator type: %s\n", gsl_rng_name (r));
fprintf (stderr,"seed = %lu\n", gsl_rng_default_seed);
fprintf (stderr,"first value = %lu\n", gsl_rng_get (r));
if (argc==1) return 0;
else {
/* spew binary data to stdout */
unsigned long random_chunk[CHUNKSIZE];
int i =0;
while (1) {
for (i = 0; i<CHUNKSIZE; ++i)
random_chunk[i] = gsl_rng_get(r);
fwrite(random_chunk, sizeof(unsigned long),
CHUNKSIZE, stdout);
}
}
/* never get here */
return 1;
}
Reply to: