Pseudo-Random Numbers (xorshift)
Shifting bits and XOR-ing them produces a stream of numbers that look random.
x ^= x << 13; x ^= x >> 17; x ^= x << 5
The same seed always gives the same sequence. The seed must not be 0.
The 32-bit version has period 2³² − 1. For cryptography or fair lotteries, use a dedicated secure generator.
Calculator
Change a value and the result and picture update instantly.
Result
1st
2nd
3rd
1st scaled to 0–1
Animated picture
The picture follows your values. Some points and shapes can be dragged.
Use in game development
Because a seed reproduces the same results, it powers daily puzzles, replays and procedural map generation.
Code example (JavaScript)
let x = seed >>> 0 || 1;
function rand() { x ^= x << 13; x >>>= 0; x ^= x >>> 17; x ^= x << 5; x >>>= 0; return x / 4294967296; }
What the symbols mean
| Symbol | Meaning |
|---|---|
seed | Seed (integer ≥ 1) |
r1 | 1st |
r2 | 2nd |
r3 | 3rd |
u | 1st scaled to 0–1 |
More formulas in this category
- Rectangle Collision (AABB)
- Circle Collision
- Linear Interpolation (lerp)
- Easing Functions
- Cubic Bézier Curves
- Projectile Path
- Reflection Vector
Frequently asked questions
- What is the formula for Pseudo-Random Numbers (xorshift)?
- The formula for Pseudo-Random Numbers (xorshift) is x ^= x << 13; x ^= x >> 17; x ^= x << 5. Shifting bits and XOR-ing them produces a stream of numbers that look random.
Math Formula Quiz Math for Game Development
Sources
Checked: 2026-11-29