Skip to content

Instantly share code, notes, and snippets.

@ydm
Created November 18, 2023 02:17
Show Gist options
  • Select an option

  • Save ydm/624603ada7c9c8d09fc18a9b0fd70a7f to your computer and use it in GitHub Desktop.

Select an option

Save ydm/624603ada7c9c8d09fc18a9b0fd70a7f to your computer and use it in GitHub Desktop.
import os
import std/parseopt
from std/strutils import join, parseUInt
from std/sequtils import mapIt, toSeq
from nimcrypto/hash import fromHex
from ../../beacon_chain/spec/digest import Eth2Digest
from ../../beacon_chain/spec/validator import compute_shuffled_index
type
Args = object
count: uint64
seed: Eth2Digest
proc parseArgs(): Args =
let s = os.commandLineParams().join(" ")
var p = initOptParser(s)
while true:
p.next()
case p.kind
of cmdEnd:
break
of cmdShortOption, cmdLongOption:
if p.key == "c" or p.key == "count":
result.count = parseUInt(p.val).uint64
elif p.key == "s" or p.key == "seed":
result.seed = Eth2Digest.fromHex(p.val)
of cmdArgument:
discard
proc main() =
# Examples:
#
# ../../env.sh nim compile --run shuffle_list.nim \
# --count=1000 \
# --seed=0xadfc4149c2caf9f25332e4fd639b0586fcf5e1a4be08a9d2cf903844df9fde3f
#
# ../../env.sh nim compile --run shuffle_list.nim \
# -c=1000 \
# -s=0xadfc4149c2caf9f25332e4fd639b0586fcf5e1a4be08a9d2cf903844df9fdef3
#
let args: Args = parseArgs()
let xs: seq[uint64] = toSeq(0'u64 ..< args.count)
let ys: seq[string] = xs.mapIt:
$compute_shuffled_index(it, args.count, args.seed)
let zs: string = ys.join(", ")
echo "[", zs, "]"
when isMainModule:
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment