Random Odd Numbers Generator
Generate random odd numbers within any range. Configure count, min/max bounds, duplicates, sorting, and export results instantly.
About
Generating uniformly distributed odd integers across an arbitrary range is not as trivial as it appears. A naive approach - generate a random integer, check if it is odd, retry if not - introduces rejection bias and unbounded loop risk at scale. This tool computes the exact cardinality of odd integers in the closed interval [a, b] and maps a uniform random index directly onto that subset, guaranteeing O(1) generation per number with zero rejections. When duplicate-free output is required, the generator builds the full odd-integer pool and applies a Fisher-Yates shuffle, which runs in O(n) time and produces an unbiased permutation. Requesting more unique values than the pool contains is detected before generation and flagged as an error - not silently truncated.
Applications range from cryptographic nonce seeding (many schemes require odd moduli) to Monte Carlo sampling on odd lattices, classroom exercises in parity, and lottery-style draws. The tool assumes a standard uniform PRNG (Math.random); it is not suitable for cryptographic key generation. Pro tip: if your range bounds are even, they are automatically narrowed inward to the nearest odd values - verify the adjusted bounds in the output summary.
Formulas
The count of odd integers in a closed interval [a, b] where a โค b is computed as:
where a is adjusted to the nearest odd ceiling and b to the nearest odd floor if they are even. More precisely, using floor division:
To generate a uniformly random odd integer without rejection, the generator maps a random index k โ {0, 1, โฆ, C โ 1} to an odd value:
where aodd is the smallest odd integer โฅ a. For duplicate-free generation, a Fisher-Yates shuffle on the pool array guarantees an unbiased permutation in O(C) time.
Where: C = total count of odd integers in range, a = minimum bound, b = maximum bound, k = uniform random index, n = generated odd number, aodd = adjusted odd minimum.
Reference Data
| Range | Odd Count Formula | Count | Example Odds | Notes |
|---|---|---|---|---|
| 1 - 10 | โ10รท2โ โ โ0รท2โ | 5 | 1, 3, 5, 7, 9 | Symmetric around 5 |
| 1 - 100 | โ100รท2โ โ โ0รท2โ | 50 | 1, 3, โฆ, 99 | Half of all integers |
| 1 - 1000 | 500 | 1, 3, โฆ, 999 | Dense pool | |
| 0 - 1 | 1 | 1 | Only one odd value | |
| โ10 - 10 | 10 | โ9, โ7, โฆ, 9 | Negative odds included | |
| โ99 - โ1 | 50 | โ99, โ97, โฆ, โ1 | Fully negative range | |
| 2 - 2 | 0 | - | No odd integers exist | |
| 7 - 7 | 1 | 7 | Single-value range | |
| 1 - 10000 | 5000 | 1, 3, โฆ, 9999 | Large pool, fast generation | |
| โ1000 - 1000 | 1000 | โ999, โฆ, 999 | Centered symmetric range | |
| 100 - 200 | โ200รท2โ โ โ99รท2โ | 50 | 101, 103, โฆ, 199 | Even bounds adjusted inward |
| 0 - 0 | 0 | - | Zero is even | |
| 1 - 2 | 1 | 1 | Minimal valid range | |
| 999 - 1001 | 2 | 999, 1001 | Tight odd-only range | |
| โ5 - 5 | 5 | โ5, โ3, โ1, 1, 3, 5 | Includes zero (even, excluded) |