Instruction
RDRAND
Returns a random number from the processor's hardware generator; CF=1 means the value is valid, CF=0 that none was ready.
- Extensions
- Forms
- 1 (1 Legacy)
- Data
- Intel XED v2026.08.23
RDRAND fills a 16-, 32- or 64-bit register with a random number from the processor’s generator and sets CF to say whether it got one. On Intel’s processors the numbers come from a deterministic generator built to NIST SP 800-90A that an on-chip entropy source reseeds often; RDSEED reads closer to that entropy source, for seeding a generator of one’s own. AMD’s manual says only that the value is generated by hardware.
Always test CF
CF = 0 means no number was ready: the generator’s self-tests rejected its output, or many cores asked faster than it could supply. Both manuals tell software to try again a limited number of times, and Intel’s suggests ten; a program that loops forever on CF = 0 hangs on a failed generator. Every run clears OF, SF, ZF, AF and PF. Zen 5 set CF on each recorded run, with the other flags cleared.
The manuals differ on the failed value. Intel’s makes the destination 0;
AMD’s only calls it invalid. Compiled code relies on Intel’s rule: for
_rdrand32_step(&x), GCC 14 at -O2 emits rdrand eax and a CMOVC that
puts 1 in EAX when CF is set, so when CF is clear the function returns
the register itself, counting on it being 0; Clang 23 does the same with
CMOVAE. Both store the register to x either way. Both need -mrdrnd or
an -march that has it, such as ivybridge or znver1; x86-64-v3 and v4 do
not.
Sizes
As with other general-purpose writes, the 32-bit form clears bits 63:32
and the 16-bit form leaves bits 63:16 alone: on Zen 5, rdrand r9w
replaced only the low 16 bits of R9.
Cost and virtual machines
AMD’s Zen 5 guide lists RDRAND and RDSEED as microcoded, with no latency given. Under Intel’s VMX a hypervisor can make every RDRAND exit to it (“RDRAND exiting”, Intel’s manual, volume 3) and answer in its place. The CPUID bit is leaf 1, ECX bit 30.
In the optimization guide
What the optimization guide says about RDRAND, a line per claim. Each links to the claim in the guide, with its sources and where they differ.
Sandy Bridge and Ivy Bridge
- What Ivy Bridge changed: Ivy Bridge adds three features: RDRAND, a hardware random number generator meeting NIST SP 800-90A; VCVTPH2PS and VCVTPS2PH, converting half-precision floats; and reading or writing the FS and GS base registers from any ring.
Silvermont to Goldmont Plus
- Instruction set and counters: Silvermont is the first Atom core with SSE4.2 and POPCNT; Goldmont Plus adds RDPID and PTWRITE.
Vulnerability mitigations
Mitigations of these processor vulnerabilities use RDRAND:
- CVE-2022-21127: Special Register Buffer Data Sampling (Special Register Buffer Data Sampling update)
- CVE-2020-0543: Special Register Buffer Data Sampling
Forms
| Instruction | Encoding | Requires |
|---|---|---|
RDRAND r16/32/64
RDRAND_GPRv | 0F C7 /6 | RDRAND |
Latency and throughput
| Model | r16 | r32r64 |
|---|---|---|
| Sandy Bridge | 100 / 0.33p015 | 100 / 0.33p015 |
| Haswell | 1 / 5.33p01235 | 1 / 5.33p01235 |
| Broadwell | 9 / 1p012356 | 9 / 1p012356 |
| Skylake, Skylake-SP, Ice Lake | 100 / 0.25p0156 | 100 / 0.25p0156 |
| Alder Lake, Sapphire Rapids | 1386 / 7p0 p1 p2 p3 p5 p6 p10 p11 | 100 / 7p0 p1 p2 p3 p5 p6 p10 p11 |
| Lunar Lake | 100 / 0.17p012345 | 100 / 0.17p012345 |
| Silvermont | 100 / 1FPC0 | 100 / 1FPC0 |
| Zen, Zen 2 | 100 / 0.25 | 100 / 0.25 |
| Zen 3, Zen 4 | 100 / 25ALU0 ALU1 ALU2 ALU3 | 100 / 25ALU0 ALU1 ALU2 ALU3 |
Operation
What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.
ok = random_ready() # the generator's: 1 when it has a
# number for RDRAND, a random one
dest.write(random(OSIZE) if ok else 0)
cf = ok # 16 bits: bits 63:16 kept; 32 bits:
of = sf = zf = af = pf = 0 # bits 63:32 cleared
# with none ready, a program tries again, a few times. Intel's
# manual says that the destination is then 0, AMD's only that it is
# not valid. Intel's RDRAND draws from a deterministic generator that
# an entropy source on the chip reseedsRun on AMD Zen 5 (EPYC 9645): 3 cases.
Operands
| Operand | Kind | Action |
|---|---|---|
RDRAND r16/32/64 | ||
r16/32/64 | explicit | write |
RFLAGS | implicit | write |
Flags
| OF | SF | ZF | AF | PF | CF |
|---|---|---|---|---|---|
| All forms | |||||
| 0 | 0 | 0 | 0 | 0 | M |
CPUID and processors
Each form belongs to an XED ISA set. A form can be used when the processor reports every CPUID bit of one of its ISA set's alternatives.
| ISA set | CPUID | Processors |
|---|---|---|
RDRAND | RDRAND | Ivy Bridge, Haswell, Broadwell, Skylake, Comet Lake, Cannon Lake, Ice Lake (client), Tiger Lake, Alder Lake, Arrow Lake, Panther Lake, Nova Lake, Skylake-SP, Cascade Lake, Cooper Lake, Ice Lake (server), Sapphire Rapids, Emerald Rapids, Granite Rapids, Diamond Rapids, Silvermont, Goldmont, Goldmont Plus, Tremont, Snow Ridge, Lakefield, Sierra Forest, Clearwater Forest, Knights Landing, Knights Mill, Zen, Zen+, Zen 2, Zen 3, Zen 4, Zen 5, Zen 6 |
Sources
- Intel XED v2026.08.23 (commit
0bcb6237345c): forms, encodings, operands, flags, exception classes, attributes, ISA sets, CPUID bits and chip model. - The CPU data of x86-64.net: Zen 3 to Zen 6, from GCC’s
-marchfeature sets and AMD’s Processor Programming References, which the page of each processor cites. - LLVM 23.1.2's x86 scheduling models (commit
85ac56026243): the latency, reciprocal throughput and ports of each form, as llvm-mca reports them. - Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 2 (325383-093, September 2026): Volume 2B, page 4-554 (RDRAND)
- Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 1 (253665-093, September 2026)
- Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 3 (325384-093, September 2026)
- AMD64 Architecture Programmer's Manual, Volume 3: General-Purpose and System Instructions (24594, rev. 3.39, October 2026)
- Software Optimization Guide for the AMD Zen5 Microarchitecture (58455, rev. 1.00, August 2024), Wayback Machine copy of AMD's ZIP
The tables are derived from Intel XED, Copyright Intel Corporation, licensed under the Apache License 2.0; x86-64.net converted and reformatted them. The timings come from LLVM's scheduling models, part of the LLVM Project, licensed under the Apache License 2.0 with LLVM Exceptions. The text is our own.