Utilvo Studio100% Client-Side Suite
HomeCalculatorsRandom Number Generator
Cryptographic CSPRNG & Uniform Distribution Engine

Random Number Generator & Sampling Simulator

Generate truly uniform random numbers across custom integer ranges. Features bias-free rejection sampling, batch processing, Fisher-Yates unique item draws, and cryptographic entropy sources.

RANDOM NUMBER GENERATOR
42

Computational Foundations: PRNG vs CSPRNG vs True Hardware Entropy

How modern computing architectures generate, scale, and validate unbiased random numbers.

Computers are inherently deterministic finite-state machines. Generating "random" numbers requires either capturing physical non-deterministic external noise (True Random Number Generators - TRNG) or expanding an initial seed state through non-linear mathematical transformations (Pseudo-Random Number Generators - PRNG).

Linear Congruential (LCG)

Basic Simulation Engine

Formula X_(n+1) = (aX_n + c) mod m. Highly vulnerable to Marsaglia's theorem (points falling into parallel hyperplanes). Fast, but cryptographically broken.

Mersenne Twister (MT19937)

Scientific Monte Carlo

Astronomical period of 2¹⁹⁹³⁷ - 1 with 623-dimensional equidistribution. Ideal for physics simulations, but predictable after observing 624 outputs.

CSPRNG (Utilvo)

Cryptographic Security

Powered by crypto.getRandomValues using ChaCha20/AES-CTR with OS entropy pooling. Unpredictable even under full adversary inspection.

Random Number Generator Algorithms Reference Matrix

Comparing periodicity, NIST statistical suite compliance, and cryptographic resilience.

Algorithm / SourcePeriod LengthNIST / DieharderCrypto SecurityPrimary Application
Web Crypto API (ChaCha20)2⁷³ bytes100% PassYes (CSPRNG)Raffles, Giveaways, Key generation, Lotteries
Mersenne Twister (MT19937)2¹⁹⁹³⁷ - 1Pass (Non-crypto)NoScientific modeling, Game physics, Monte Carlo
xorshift128+ (V8 Engine)2¹²⁸ - 1Minor FailuresNoDefault browser Math.random() implementation
Linear Congruential (ANSI C)2³²FailNoLegacy embedded systems, simple non-critical code
Hardware TRNG (Thermal Noise)Infinite (Aperiodic)100% PassYes (Hardware)OS entropy pools (/dev/urandom), CPU RDRAND

Modulo Bias Elimination via Rejection Sampling

Why naïve modulo formulas introduce statistical favoritism and how to eliminate it.

When scaling a 32-bit random integer (range 0 \dots 2³² - 1 = 4,294,967,295) to a custom window of size R, developers frequently use the modulo operator val % R. However, unless R is an exact power of two, 2³² is not evenly divisible by R. The remainder values at the bottom of the range receive an extra possible outcome, systematically biasing draws toward lower numbers.

The Exact Rejection Sampling Solution

limit = (2³² - (2³² % range))
do { raw = crypto.getRandomValues(uint32)[0]; } while (raw >= limit);
return min + (raw % range);

By discarding the negligible slice of values greater than or equal to limit, every integer in the designated window receives an identically equal probability of selection down to absolute mathematical parity.

Sampling With Replacement vs Fisher-Yates Permutations

How unique number generation operates without performance degradation or infinite loops.

Sampling With Replacement

Independent Draws

Each draw has zero memory of previous numbers. The probability of picking any specific value remains constant at 1 / (Max - Min + 1). Duplicates naturally occur according to the Birthday Paradox.

Sampling Without Replacement

Fisher-Yates Shuffle

Guarantees that every generated number in the batch is strictly unique. Utilizes the O(k) modern Fisher-Yates partial shuffle to extract unbiased items in linear time without retry stalls.

Worked Case Studies & Probabilistic Scenarios

Concrete practical applications in giveaways, scientific trials, and statistical tests.

Scenario 1: Verifiable Contest Raffle — 3 Unique Winners from 1,250 Entries

Contest Audit

An organization has 1,250 numbered ticket entries (#1 to #1250) and must select 3 distinct grand prize winners without duplicate selections.

• Configuration: Min = 1, Max = 1250, Quantity = 3, Allow Duplicates = False
• Total Permutations: 1,250 × 1,249 × 1,248 = 1,948,440,000 ordered triplets
• Unbiased Probability: Each participant has an exact 3 / 1,250 = 0.24% winning chance
• Audit Trail: Generated numbers [342, 891, 104] are recorded with timestamp and cryptographic seed hash

Scenario 2: Clinical Trial Randomized Treatment Allocation (A vs B)

Medical Research

A medical research team must randomly allocate 20 enrolled patients to either Treatment Arm A (assigned to odd integers) or Control Arm B (assigned to even integers) between 1 and 100.

• Configuration: Min = 1, Max = 100, Quantity = 20, Allow Duplicates = False
• Odd Numbers (Treatment A): Allocated immediately upon generation
• Even Numbers (Control B): Allocated immediately upon generation
• Outcome: Eliminates clinician selection bias and provides audited assignment sheets

Scenario 3: Chi-Square Uniformity Test — Validating 10,000 Draws

Statistical Quality

To verify that numbers between 1 and 10 are uniformly distributed, 10,000 iterations are run and grouped into 10 buckets (Expected frequency E = 1,000 per bucket).

• Formula: χ² = Σ ((Observed - 1000)² / 1000) for degrees of freedom df = 9
• Observed χ² Value: 7.84
• Critical Threshold (p = 0.05, df = 9): 16.92
• Conclusion: Because 7.84 < 16.92, the hypothesis of uniform distribution is confirmed with 95%+ confidence

How to Generate Random Numbers Step-by-Step

Follow these four simple steps to configure and generate uniform random numbers.

1

Set Range Boundaries (Min & Max)

Define the minimum and maximum integer values for your target random number generation window.

2

Specify Quantity & Duplication Rules

Choose how many numbers to generate and check or uncheck 'Allow Duplicates' depending on whether you require unique items.

3

Execute Random Generation

Click Generate to trigger the cryptographic PRNG engine and immediately receive uniformly distributed values.

4

Copy, Sort, or Export Numbers

Sort outcomes numerically, inspect sequence statistics, or copy the comma-delimited output directly to your clipboard.

Frequently Asked Questions

Everything you need to know about modulo bias, sampling methods, and cryptographic entropy.

How does the random number generator prevent modulo bias?

Instead of a simple modulo operator which over-represents lower numbers when the range does not evenly divide 2^32, the engine employs rejection sampling to discard out-of-bounds entropy words before scaling.

What is the difference between sampling with replacement versus without replacement?

Sampling with replacement treats each draw independently, allowing numbers to repeat. Sampling without replacement (disallowing duplicates) utilizes the Fisher-Yates shuffle algorithm to guarantee that every selected number in the batch is strictly unique.

Is this RNG suitable for cryptographic key generation and sensitive lotteries?

Yes. The generator interfaces directly with the browser's Web Cryptography API (crypto.getRandomValues), drawing high-entropy seeds directly from operating system hardware sources rather than deterministic math algorithms.

What are the maximum and minimum boundaries for integer generation?

You can generate integers spanning from negative 1,000,000,000 to positive 1,000,000,000, with batch sizes up to 1,000 unique values per calculation cycle.

Does generating random numbers send my data or results to remote servers?

No. All random number generation routines, array permutations, and uniqueness validations execute 100% on the client side in your web browser with complete privacy.

Companion Suite

Complementary client-side utilities to streamline your workflow.

Browse All Calculators →