You need to toss a coin. But why settle for the best of 3? cointoss3000 gives you the best of 3000.
- make
- go
make./ct3Sample output:
heads
Use -t <number of tosses>. For example, if you want the best of 3,
./ct3 -t 3Of course, as the proud owner of cointoss3000, you won't want to limit yourself to a mere three coin tosses.
cointoss3000 is capable of tossing a coin up to 2^64 - 1 times. This will take a long time.
./ct3 -t 18446744073709551615Overflowing the uint64 is not allowed. Sorry, Matt Parker.
# not allowed
./ct3 -t 18446744073709551616# not allowed
./ct3 -t -1If you want to know how many heads and tails you got, pass the -v flag.
./ct3 -vSample output:
heads: 1546
tails: 1454
winner: heads
cointoss3000 can be run as an HTTP server. It listens for GET /
requests on a customisable port. To run it as a server, use the
-s <port> flag. For example, to run it on port 8080,
./ct3 -s 8080You can now curl it:
$ curl localhost:8080
tailsNote that other flags are not allowed when using the
-sflag. Use the query parameters instead.
You can set verbose output with the query parameter v. Example:
$ curl 'localhost:8080?v'
heads: 1459
tails: 1541
winner: tailsYou can set the number of tosses with the t= parameter. Example:
$ curl 'localhost:8080?v&t=3'
heads: 0
tails: 3
winner: tailsNote:
- If the verbose flag is not set, only 1 toss is performed to save production CPU cycles.
- The maximum number of tosses is 10,000 to prevent cointoss3000 from getting slammed in production.
- Rate limiting is left as an exercise for the reader.
BSD 3-Clause. See LICENCE for full text.