Skip to content

Instantly share code, notes, and snippets.

@hexagon5un
Created March 30, 2023 10:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hexagon5un/2e9066e0a3148db5aead17ceb1c55d3b to your computer and use it in GitHub Desktop.
Save hexagon5un/2e9066e0a3148db5aead17ceb1c55d3b to your computer and use it in GitHub Desktop.
#! /bin/env bash
[ $# -eq 0 ] && echo "Usage: randomNIST number_contestants [pulseIndex]" && exit
[ $# -eq 1 ] && number_contestants=$1 && pulseIndex=last
[ $# -eq 2 ] && number_contestants=$1 && pulseIndex=$2
# convert to hexadecimal
number_contestants=$(echo "ibase=10 ; obase=16 ; $number_contestants" | bc)
randomHex=$(curl https://beacon.nist.gov/beacon/2.0/chain/2/pulse/${pulseIndex} | grep outputValue | cut -d \" -f 4)
# and the winner is....
# curl https://beacon.nist.gov/beacon/2.0/chain/2/pulse/${pulseIndex} | grep pulseIndex | cut -d : -f 2
# echo $randomHex
echo "scale=0 ; ibase=16 ; $randomHex % $number_contestants" | bc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment