Last active
November 10, 2023 23:36
-
-
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/469c4bbf63806dcc3a2009aa1a4b15d4838f19d0
This file contains 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.3.1" | |
//> 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