summaryrefslogtreecommitdiff
path: root/apps/JAWS/clients/WebSTONE/src/genrand.c
blob: 3aad47794fb1aeeeaa6d94eabe3942ad06b088e2 (plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**************************************************************************
 *									  *
 * 		 Copyright (C) 1995 Silicon Graphics, Inc.		  *
 *									  *
 *  These coded instructions, statements, and computer programs were	  *
 *  developed by SGI for public use.  If any changes are made to this code*
 *  please try to get the changes back to the author.  Feel free to make  *
 *  modifications and changes to the code and release it.		  *
 *									  *
 **************************************************************************/
#include <stdio.h>
#include <fcntl.h>
#include <math.h>

#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "sysdep.h"

void
main(const int argc, char* argv[])
{
    FILE* file;
    int i;
    int my_random;
    int size;
    char *cp;

    if (argc != 3) {
	printf("usage: %s file_size_in_bytes[K|M] name\n", argv[0]);
	exit(2);
    }

    if ((file = fopen(argv[2], "w")) == NULL) {
	perror("fopen");
	exit(1);
    }

    size = atoi(argv[1]);
    for (cp = argv[1]; *cp; cp++) {
	switch(*cp) {
	    case 'k':
	    case 'K':
		size *= 1024;
		break;
	    case 'm':
	    case 'M':
		size *= 1024*1024;
		break;
	}
    }

    for (i = 0; i < size; i++) {
	my_random = ((RANDOM() % 94) + 33);
	fputc((char)my_random, file);
    }

    fclose(file);
}