Skip to content

zaljubouri/twitch-rand

Repository files navigation

twitch-rand

A random number generator powered by the top 100 current streams' Twitch chats, written in TypeScript and React. This is currently hosted at www.twitch-rand.com.

The algorithm is based off of NIST's Hash_DRBG outlined in their Recommendation for Random Number Generation Using Deterministic Random Bit Generators. The seeding follows Fortuna-style pools. Further information about process and creation is described in a two-part series here.

Usage

Regular

Clone the repository, then use yarn or npm to install the node modules:

yarn install

Copy/rename the .env.example files as .env and enter the required information, then build the website and transpile the server from the root directory:

yarn build

Start the server:

yarn start

You can then go to http://localhost:8080 (or whichever Express port you chose to use) to see the accompanying website.

Docker

You can also run and use this project as a Docker image with the provided Dockerfile after filling the .env files:

docker build . -t twitch-rand:latest
docker run -p 8080:8080 -p 8081:8081 --env-file .env --name twitch-rand twitch-rand:latest

Tests

Tests can run with or without integration tests, as they require Twitch API keys:

yarn test # with integration tests (requires .env containing Twitch API client ID and secret in server folder)
yarn test-ci # without integration tests

API

To generate random numbers, a GET method with route /random exists once the server is running. It takes the following query parameters:

Parameter Default Validation Description
bits 32 Must be between 1 and 524,288 Bit-length of the numbers generated by the RNG.
min 0 Must be less than the max The minimum generated number.
max 2^bits Must be more than the min and less than 2^bits The maximum generated number.

Example query

/random?bits=32&min=1&max=100 # returns 85

About

A random number generator powered by the top 100 current streams' Twitch chats.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published