File: randomgen2.c

package info (click to toggle)
reprepro 1.3.1%2B1-1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 1,660 kB
  • ctags: 1,621
  • sloc: ansic: 22,424; sh: 2,032; python: 138; makefile: 127
file content (35 lines) | stat: -rw-r--r-- 631 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

typedef unsigned char uchar;

const char values[] = "aaaaaaaaa: \t\r\n\n";

static inline uchar getrandom(void) {
	long r = random() % sizeof(values);
	return values[r];
}

int main(int argc, const char *argv[]) {
	int size;

	if( argc != 3 ) {
		fprintf(stderr,"Syntax: randomgen <size> <randomseed>\n");
		return EXIT_FAILURE;
	}
	size = atoi(argv[1]);
	srandom(atoi(argv[2]));

	while( size-- > 0 ) {
		unsigned char c;

		c = getrandom();
		write(1,&c,1);
	}
	return EXIT_SUCCESS;
}