Skip to content

Commit 25f9e9d

Browse files
committed
Update to README and CLI.
1 parent fbf1ec8 commit 25f9e9d

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

README.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
# The Amplified Loaded Dice Roller
22

3-
This repository contains a reference implementation in C
4-
of the Amplified Loaded Dice Roller (ALDR),
5-
a fast algorithm for rolling an $n$-sided die.
3+
This repository contains a reference implementation in C of the Amplified
4+
Loaded Dice Roller (ALDR), a fast algorithm for generating rolls an
5+
$n$-sided die with rational probabilities.
66

7-
## Building and Installing
7+
## Building
88

99
The library can be built by running
1010

1111
$ make all
1212

13-
This command creates several artifacts in the `build/` directory:
13+
This command creates the following artifacts in the `build/` directory:
1414

15-
1. `build/lib/libaldr.a`: A static C library for C programs that use ALDR.
15+
| Folder | Description |
16+
| -------- | ------- |
17+
| `build/bin/aldr` | Executable for command line interface to ALDR |
18+
| `build/include` | Header files for C programs that use ALDR |
19+
| `build/lib/libaldr.a` | Static library for C programs that use ALDR |
1620

17-
1. `build/include`: Contains header files for C programs that use ALDR.
18-
19-
1. `build/bin`: Contains the executable for a command line interface to ALDR.
2021

2122
## Usage
2223

@@ -47,14 +48,15 @@ int main(int argc, char **argv) {
4748
4849
## Usage (Command Line Interface)
4950
50-
The executable has the following command line interface:
51+
The executable in `build/bin/aldr` has the following command line interface:
5152
5253
```
53-
usage: ./build/bin/aldr num_samples ...distribution...
54+
usage: ./build/bin/aldr <n> <dist>
5455
```
5556
56-
where `num_samples` is the number of samples to draw;
57-
`...distribution...` is a space-separated list of positive integer weights.
57+
where `<n>` is an integer denoting the number of samples to draw; and
58+
`<dist>` is a space-separated list of positive integers weights for
59+
the desired discrete distribution.
5860
5961
For example, to generate 90 samples from { 1, 1, 2, 3, 2 }, run the following:
6062

sample.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
int main(int argc, char **argv) {
1515
if (argc < 3) {
16-
printf("usage: %s num_samples ...distribution...\n", argv[0]);
16+
printf("usage: %s <n> <dist>\n", argv[0]);
1717
exit(0);
1818
}
1919
int num_samples = atoi(argv[1]);
@@ -26,21 +26,15 @@ int main(int argc, char **argv) {
2626
}
2727

2828
// Obtain the samples.
29-
int *samples = calloc(num_samples, sizeof(*samples));
29+
int sample;
3030
struct aldr_s x = aldr_preprocess(a, n);
3131
for (int i = 0; i < num_samples; ++i) {
32-
samples[i] = aldr_sample(&x);
33-
}
34-
35-
// Print the samples.
36-
for (int i = 0; i < num_samples; ++i) {
37-
printf("%d ", samples[i]);
32+
printf("%d ", aldr_sample(&x));
3833
}
3934
printf("\n");
4035

4136
// Free the heap.
4237
free(a);
43-
free(samples);
4438
aldr_free(x);
4539

4640
return 0;

0 commit comments

Comments
 (0)