Client libraries

Version 2.0.0, free under the MIT license. Each library uses your CPU's own hardware generator and calls the rdrand.com API only when it has none, or if the hardware ever fails to deliver. Results have the API's formats either way.

Node.js

Node 18+ · no dependencies

Promise-based, with TypeScript types. Works with require and import.

Download jebtek-rdrand-2.0.0.tgz
npm install https://rdrand.com/Downloads/jebtek-rdrand-2.0.0.tgz
const { RdRand } = require("@jebtek/rdrand");
const rng = new RdRand();
await rng.generateKey(32);     // "kq9ZLx0t…"
await rng.generateBytes(16);   // Buffer
await rng.generateUInt();      // 0 to 2147483647
rng.source;                    // "rdrand", "rndr" or "service"

Kotlin / Java

JVM 11+ · Kotlin stdlib only

One jar with the hardware library for every platform inside. Blocking calls that take microseconds on hardware.

Download rdrand-kotlin-2.0.0.jar
implementation(files("libs/rdrand-kotlin-2.0.0.jar"))
import com.jebtek.rdrand.RdRand

val rng = RdRand()
rng.generateKey(32)
rng.generateBytes(16)          // ByteArray
rng.generateUInt()             // 0 to Int.MAX_VALUE
rng.source                     // RDRAND, RNDR or SERVICE

Rust

crate source · MSRV 1.80

RDRAND and RNDR built in. The API fallback is the default service feature; turn it off for a dependency-free, hardware-only crate.

Download rdrand-rust-2.0.0.zip
rdrand-client = { path = "rdrand-client-2.0.0" }   # Cargo.toml, after unzipping
let rng = rdrand_client::Client::new();
rng.generate_key(32)?;
rng.generate_bytes(16)?;       // Vec<u8>
rng.generate_uint()?;          // 0 ..= 2^31 - 1
rng.source();                  // Source::Rdrand, Rndr or Service

.NET

.NET Standard 2.0 · no dependencies

For .NET 6/8/9+ and .NET Framework 4.6.1+. Async and blocking methods.

Download JebteK.RdRand.2.0.0.nupkg
dotnet add package JebteK.RdRand --version 2.0.0 --source <folder with the .nupkg>
using JebteK.RdRand;

using var rng = new RdRandClient();
await rng.GenerateKeyAsync(32);
await rng.GenerateBytesAsync(16);   // byte[]
await rng.GenerateUIntAsync();      // 0 to 2147483647
rng.Source;                         // Rdrand, Rndr or Service

Where the hardware path works

The Node.js, Kotlin and .NET packages bundle a small native library for each platform; the Rust crate compiles the instructions directly. Anywhere else, the libraries use the API.

PlatformHardware sourceExamples
Linux x64, Windows x64, macOS x64RDRANDIntel and AMD servers and PCs, AWS c/m/r/t instances
Linux arm64 with ARMv8.5 RNGRNDRAWS Graviton3 and Graviton4 (c7g, m7g, c8g, …)
Linux arm64 without RNGAPIAWS Graviton2 (t4g, c6g, …), Raspberry Pi
macOS arm64APIApple silicon has no RNDR
  • Modes: auto (default: hardware, else API), hardware (fails without a hardware generator) and service (API only).
  • Checks: every hardware draw's success flag is checked and retried, the generator must pass a self-test before use, and stuck values are rejected.

Legacy

RdRandom-v1_1.zip: the original .NET Framework API wrapper (requires RestSharp; calls the API only).

string key = RdRandom.Randomizer.GenerateKey(32);
byte[] bytes = RdRandom.Randomizer.GenerateBytes(16);
uint n = RdRandom.Randomizer.GenerateUInt();