跳到正文

个人记录

基于 Intel CPU 功能自带的 rdrand 指令的随机数的产生使用例

ViynaNokphia约 1 分钟
原文
文章信息与版本

文章信息

发布
2023年11月13日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 1 分钟
获赞
2

版本

  1. v1当前
C++
#include <cstdint>
#include <iostream>
using namespace std;

int rdrand64_step(uint64_t* rand)
{
	unsigned char ok;

	asm volatile("rdrand %0; setc %1"
				 : "=r"(*rand), "=qm"(ok));

	return (int)ok;
}

int main()
{
	uint64_t x;
	int res = rdrand64_step(&x);
	cout << res << ' ' << x << '\n';
}

内嵌汇编(x

原文
存档评论4 条抓取于