Re: /dev/random and dd

[email protected]
Newsgroups gmane.linux.tomsrtbt
Message-ID <[email protected]>
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
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.