Skip to content

StartWhich API?

Which API?

Answer at most two questions about the value you need, and get the API to use, its call and what to watch for.

Pick the API for the value you need. Answer the questions, then read the card for your API below, with its call, what to watch for and the guide that goes further.

  1. Is the value a secret, or must others recompute it?
    • A secret that an attacker must not predict: go to step 2.
    • A value that others recompute from a public beacon round: go to step 3.
  2. Does your code use dependency injection?
  3. Are you running the draw or checking one?
For secrets

ISecureRandom from AddRandomness()

Keys, tokens, salts, nonces, passwords and any value an attacker must not predict, in an application with dependency injection.

  • Safe for secrets: yes
  • Reproducible by others: no
  • Needs dependency injection: yes
The call
public sealed class TokenService(ISecureRandom random)
{
private const string Alphabet = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
public string NewRecoveryCode() => random.GetString(Alphabet, 16);
public int RollDie() => random.NextInteger(1, 7);
}
Watch for
Fill a key into a span you clear; never keep it in the byte[] GetBytes returns.
For secrets

RandomnessHost

The same generator and beacons in a console tool or library with no dependency injection.

  • Safe for secrets: yes
  • Reproducible by others: no
  • Needs dependency injection: no
The call
// The Randomness section of any IConfiguration.
var section = configuration.GetSection(RandomnessOptions.SectionName);
var builder = RandomnessHost.CreateBuilder(section);
builder.AddCurbyBeacon().AddNistBeacon().AddDrandBeacon();
await using var randomness = await builder.BuildAsync(cancellationToken);
Guid id = randomness.SecureRandom.NextGuid();
Watch for
Dispose it: disposing stops the beacon loops and zeroes the generator's state.
For secrets

SystemRandomSource.Instance

The operating system's generator behind the same API, with no beacon and nothing to dispose.

  • Safe for secrets: yes
  • Reproducible by others: no
  • Needs dependency injection: no
The call
Guid id = SystemRandomSource.Instance.NextGuid();
Watch for
No beacon input is mixed in; register beacons with AddRandomness() or RandomnessHost for that.
For draws others check

IVerifiableRandomFactory

A raffle, audit sample or jury selection that anyone can recompute from a committed beacon round.

  • Safe for secrets: no
  • Reproducible by others: yes
  • Needs dependency injection: yes
The call
using var draw = await draws.CreateAsync(
"curby",
round: 1620423,
context: "example-raffle-2026-11-25",
cancellationToken
);
var winner = entrants[draw.NextInteger(0, entrants.Length)];
// Publish draw.Pulse.Id with the result, so anyone can recompute it.
Watch for
Commit to the round and the context before the round is published, and never derive a secret from a draw.
For draws others check

A beacon's verifier and VerifiableRandom.Create

Recompute a published draw from the documents its beacon served, without the network.

  • Safe for secrets: no
  • Reproducible by others: yes
  • Needs dependency injection: no
The call
var pulse = new CurbyPulseVerifier().Verify(
chainJson,
pulseJson,
predecessorJson
);
using var draw = VerifiableRandom.Create(pulse, context);
var bytes = draw.GetBytes(32);
var first = Convert.ToHexStringLower(bytes);
var rolls = Enumerable
.Range(0, 5)
.Select(_ => draw.NextInteger(1, 101))
.ToArray();
// first is e43e360c9e2b9cd6a094e04a64e65922a3581ba6864da1cb1490244522f9986e,
// and rolls is 80, 38, 69, 95, 91, the values the reference
// implementation in docs/draws.md prints for this pulse and context.
Watch for
A verifier proves the documents are authentic, not that they are the committed round: compare Round and Id.

Every beacon, side by side: the beacons.