Re: /dev/random and dd

"Yan Fitterer" <[email protected]>
Newsgroups gmane.linux.tomsrtbt
Organization Royal Academy of Music
Message-ID <3CEB80E0.1806.AD59CB@localhost>
Whow... After some trouble trying to compile it under libc5  (gave up on that one - 
I'm on RH7.2), I ended up doing a static then strip against my libc6. That required 
a little rming in tomsrtbt...

Anyway. Performance is now much improved, although not yet enough to keep 
the HD busy on the old hardware I'm using. I'm getting about 300k/s, but the HD 
could do probably about 3 times that (tried a few old machines). I guess there will 
be a break-even point, as processors increase in speed much more than bus/hd - 
so it should be OK on newer hardware - but on the stuff I'm running at the 
moment, it's still a little slow.

If a faster version springs to mind, let me know. I'll try and see if I can compile 
GNU's shred for tomsrtbt in the meantime. But I'm _not_ a C programmer (at all), 
so I may not go very far...

Thanks ever so much, help much apreciated.

Yan


----  On 21 May 2002, at 15:32, [email protected] wrote:  ----

> On Tue, 21 May 2002 [email protected] wrote:
> 
> > Am I right then in thinking there's really no easy solution with Linux? (short of 
> > leaving the dd running overnight, or mounting the HD in another (faster) machine...)
> 
> There are kerjillions of easy ways of doing it with Linux :).
> 
> You could write a simple program that uses standard library random
> function for generating random data. That should be way faster than
> /dev/*random as its should have a rather plainforward implementation.
> 
> Then you can direct its output to /dev/hda or use dd if you wish.
> 
> More than 5,6 megabytes under 3 seconds with the following:
> --------------------------------------------------------
> #include <stdlib.h>
> #include <stdio.h>
> #include <errno.h>
> 
> int main(int argc, char *argv[]){
>         int seed;
>         if (argc != 2){
>                 printf ("Usage: %s [seed], "
>                         "where seed can be any integer.\n", argv[0]);
>                 exit (1);
>         }
>         errno=0;
>         if ((seed = atol(argv[1])) && !errno)
>                 srand(seed);
>         else {
>                 printf ("Error: %s: %s\n", argv[1],
>                         errno ? "Numerical result out of range." : "Not a  number.");
>                 exit (2);
>         }
>         while (1) printf("%d",rand());
> }
> 
> Compile it with
> gcc -o rand rand.c
> and strip symbols with
> strip -s rand
> and you'll get a 3kB binary that should fit into tomsrtbt easily.
> 
> Usage:
> rand 12347 | dd of=/dev/hda
> or
> rand 12347 > /dev/hda
> 
> 
> Drop me a note if you need a smaller or faster version -- printf is
> overhead, using library rand() is also overhead. I guess it can be done
> under 1 kB and considerably faster than with stdlib rand(), as the latter
> uses long integers.
> 
> Regards,
> m
> 


-- 
Yan Fitterer
IT Manager, Royal Academy of Music
E-mail : [email protected]
Marylebone Rd, London, NW1 5HT
Phone (+44) 20 7873 7365 Fax (+44) 20 7873 7364
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.