Last active
May 25, 2024 08:39
-
-
Save dacr/317f02ba962be481e38134875947f225 to your computer and use it in GitHub Desktop.
using random.org random generator to generate true random number / published by https://github.com/dacr/code-examples-manager #a79f4f26-80a8-413a-a363-8dbaf3e12267/b470a246aad29771e8171fd1f85db7843f38a4de
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// summary : using random.org random generator to generate true random number | |
// keywords : scala, random, rng | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : a79f4f26-80a8-413a-a363-8dbaf3e12267 | |
// created-on : 2021-06-23T14:09:23+02:00 | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : scala-cli $file | |
// --------------------- | |
//> using scala "3.4.2" | |
//> using dep "com.lihaoyi::requests:0.8.0" | |
//> using dep "com.lihaoyi::upickle:3.1.3" | |
// --------------------- | |
import ujson.Obj, scala.util.Properties.envOrNone | |
envOrNone("RANDOM_ORG_API_KEY") match { | |
case None => println("Signup to random.org, create an api key or reuse an existing one - https://api.random.org/dashboard") | |
case Some(key) => | |
val api = "https://api.random.org/json-rpc/4/invoke" | |
val query = Obj( | |
"jsonrpc" -> "2.0", | |
"method" -> "generateIntegers", | |
"id" -> 42, | |
"params" -> Obj( | |
"apiKey" -> key, | |
"n" -> 1, | |
"min" -> 0, | |
"max" -> 999, | |
"n" -> 5, | |
"replacement" -> false // for distinct values | |
) | |
) | |
val response = requests.post(api, data = query) | |
println(response.text()) | |
//println(upickle.default.read[Response](response.text())) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment