eDice Developer’s Edition: A Complete Guide to Integration & APIsIntroduction
eDice Developer’s Edition is a toolkit aimed at developers building digital dice, randomization engines, and interactive probability tools for tabletop gaming, simulations, education, and testing. This guide covers the architecture, APIs, integration patterns, scripting, best practices for reliability and fairness, and practical examples showing how to embed eDice into web, mobile, and server environments.
What eDice Developer’s Edition provides
- SDKs for multiple platforms: JavaScript (browser/Node), Python, and a lightweight REST API for language-agnostic integrations.
- Deterministic and non-deterministic RNG options: cryptographically secure RNG for fairness, and seeded PRNGs for reproducible sessions.
- Rich die models: standard d6/d20/etc., custom polyhedral dice, weighted/fudged dice, and compound outcomes (exploding dice, rerolls, success thresholds).
- Event hooks and webhooks: receive notifications for key events (roll start/end, session creation), useful for multiplayer and cloud services.
- Analytics and logging: optional anonymized telemetry to track usage patterns and detect biased outcomes.
- Sandbox and test harness: run millions of simulated rolls to verify distributions and detect implementation errors before production.
Architecture overview
eDice Developer’s Edition typically separates concerns into three layers:
- Client SDKs — handle UI interactions, local roll display, and optional local RNG.
- Service layer (optional) — a hosted or self-hosted service exposing REST/gRPC endpoints for roll generation, session management, and matchmaking.
- Persistence and analytics — stores sessions, user preferences, and anonymized roll aggregates for analytics.
This separation allows low-latency local rolls while also supporting centralized features like cross-player consistency, fraud prevention, and replayability.
API types and usage patterns
REST API (language-agnostic)
Common endpoints:
- POST /sessions — create a game session (returns session_id, seed if deterministic)
- POST /rolls — perform a roll (body: session_id, dice array, options)
- GET /rolls/{id} — fetch roll result and metadata
- POST /webhooks — register webhook for session events
- GET /analytics — retrieve anonymized aggregate data
Typical request (JSON):
{ "session_id": "s_12345", "dice": [ {"type":"d20","count":1}, {"type":"d6","count":3,"explode":"6"} ], "options": {"seed":"seed123","secure":true} }
JavaScript SDK (browser/Node)
- Initialize:
import { eDiceClient } from 'edice-js'; const client = new eDiceClient({ apiKey: 'YOUR_KEY' });
- Create session and roll:
const session = await client.createSession({ userId: 'alice', deterministic: true }); const result = await client.roll(session.id, [{ type: 'd20' }]); console.log(result.total, result.details);
Python SDK
- Install and use:
from edice import Client client = Client(api_key='YOUR_KEY') session = client.create_session(user_id='bob', deterministic=True) res = client.roll(session.id, [{'type':'d6','count':4}]) print(res['total'])
RNG options and fairness
- Cryptographically Secure RNG (CSPRNG): use for public games or gambling-like applications. Ensures unpredictability and tamper resistance.
- Seeded PRNG: useful for reproducible playtesting and replays. eDice provides deterministic seeding using HMAC-SHA256 of session seed + roll index.
- Hybrid mode: local client uses PRNG for immediate UI feedback while server confirms final result with CSPRNG; client UI marks results as provisional until server confirmation.
Best practices:
- Always log seed and nonce for deterministic sessions to allow replay.
- Use CSPRNG when fairness must be provable; offer users a way to verify seeds (e.g., publish seed commitments before revealing results).
- Run statistical tests (chi-square, Kolmogorov–Smirnov) during QA to detect bias.
Advanced die models
- Exploding dice: when a die hits a threshold (e.g., 6 on d6), roll again and add. eDice supports recursion limits and probability caps to prevent runaway rolls.
- Success thresholds: count successes when faces meet a criterion (>= target). Useful for narrative RPG systems.
- Weighted/biased dice: support custom face weights for simulating loaded dice — useful for testing and specialized gameplay.
- Compound outcomes: roll sets of dice and map results to complex outcomes (damage tables, critical effects).
Example: exploding d6 server-side pseudo-request
{ "dice":[{"type":"d6","count":1,"explode":{"on":6,"limit":5}}] }
Webhooks & real-time integration
- Webhooks: notify your service when sessions are created, rolls completed, or disputes raised. Include HMAC signatures to validate payloads.
- WebSockets / PubSub: for real-time multiplayer, subscribe to room channels to broadcast provisional and final roll results.
- Conflict resolution: decide whether the server authoritative result overrides client-side provisional values; maintain immutable roll IDs to avoid tampering.
Embedding into web and mobile apps
- Web (SPA): use the JavaScript SDK for UI interactions. Show provisional UX (spinning die) immediately, patch with confirmed server result. Cache session seeds in localStorage for reproducibility.
- Mobile (iOS/Android): either use REST or embed native SDKs (if available). Use platform secure storage for API keys and session tokens.
- Offline mode: support local-only PRNG rolls while queuing events for server sync when back online; mark offline rolls as non-authoritative.
Security, privacy, and compliance
- Store minimal personal data. Use anonymous session tokens where possible.
- Use TLS for all API traffic. Validate webhook signatures.
- Rate-limit endpoints and monitor for abnormal roll patterns (botting/fraud).
- If used in gambling contexts, comply with local laws and consider third-party audits for RNG.
Testing, QA, and analytics
- Unit-test roll logic with mocked RNGs to assert deterministic outcomes.
- Run large-scale simulations to verify distribution uniformity (e.g., 10M d6 rolls).
- Track analytics: average roll times, distribution skew, most-used die types. Present aggregated dashboards without exposing individual player data.
Example integrations
- Virtual Tabletop: integrate eDice to ensure consistent outcomes across all players; server authoritative with client provisional feedback.
- Educational app: use deterministic seeded modes so teachers can reproduce lesson scenarios.
- Board game companion: incorporate compound outcomes to resolve card-driven events.
Best practices & troubleshooting
- Use session seeds and immutable roll IDs for auditability.
- Surface clear UI states: provisional → confirmed → archived.
- Handle network failures gracefully: queue and reconcile.
- Monitor for bias and have a plan (e.g., rotate RNG provider, update algorithm) if issues appear.
Conclusion
eDice Developer’s Edition combines flexible APIs, multiple RNG choices, and tools for fairness and reproducibility. Whether you’re building a virtual tabletop, a teaching aid, or a game service, use deterministic modes for replays, CSPRNG for fairness, and robust session management for multiplayer consistency.
Leave a Reply