/
randFileEx.c
52 lines (42 loc) · 2.25 KB
/
randFileEx.c
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
/* -*- Mode:C; Coding:us-ascii-unix; fill-column:132 -*- */
/* ****************************************************************************************************************************** */
/**
@file randFileEx.c
@author Mitch Richling <https://www.mitchr.me/>
@Copyright Copyright 1990 by Mitch Richling. All rights reserved.
@brief Demonstrate how to use a random number file@EOL
@Keywords random number file
@Std C89
This program shows how to use my randFile library to obtain a random sequence of chars, ints, or longs from a random bit sequence
file.
*/
/* ------------------------------------------------------------------------------------------------------------------------------ */
#include <stdio.h> /* I/O lib ISOC */
#include <stdlib.h> /* Standard Lib ISOC */
/* ------------------------------------------------------------------------------------------------------------------------------ */
#include "randFileC.h"
/* ------------------------------------------------------------------------------------------------------------------------------ */
int main(int argc, char *argv[]) {
int ranGen;
int i;
if(argc < 2) {
printf("ERROR: Must provide a file name as the first argument\n");
exit(1);
}
/* Initialize random number generator. */
ranGen = newFileRand(argv[1]);
/* Three sizes of random number: char, int, and long.
Three types for each size: S=signed, SNN=signed non-negative, U=unsigned
Function names constructed like so: genFileRand<size><types>() */
printf("%3s %7s %7s %7s %12s %12s %12s %22s %22s %22s\n", "idx",
"charS", "charSNN", "charU", "intS", "intSNN", "intU", "longS", "longSNN", "longU");
for(i=0; i<25; i++) {
printf("%3d %7ld %7ld %7ld %12ld %12ld %12ld %22ld %22ld %22lu\n", i,
(long)genFileRandCharS(ranGen), (long)genFileRandCharSNN(ranGen), (long)genFileRandCharS(ranGen),
(long)genFileRandIntS(ranGen), (long)genFileRandIntSNN(ranGen), (long)genFileRandIntS(ranGen),
(long)genFileRandLongS(ranGen), (long)genFileRandLongSNN(ranGen), (long)genFileRandLongS(ranGen));
}
/* Free up resources used by random number generator */
delFileRand(ranGen);
return 0;
}