Intel's third-generation CPU core processor in the IVB architecture (which began to be produced in 2012) has a built-in feature that uses resistance thermal noise to obtain real hardware random numbers.
Philosophical arguments about the differences between real and pseudo-random numbers and whether real random numbers exist in the world are not covered in this article.
The following shows the Delphi Code. There are four functions in total. Two functions are used:
Rdrand_issupported checks whether the current CPU supports this function,
Rdrand_16 gets a 16-bit random number to the Aex register. To obtain a 32-bit or 64-bit random number, please refer to the intel development manual to modify the corresponding instructions. In addition, this function does not determine whether the CPU supports this command. Therefore, call rdrand_issupported at the beginning of the program or elsewhere to determine whether the CPU supports this function.
Function getcpuid (): uint;
VaR
Bexception: bool;
// Szcpu: array [0 .. 15] of byte;
Ucpuid: uint;
Begin
Result: = 0;
// Zeromemory (@ szcpu, sizeof (szcpu ));
Ucpuid: = 0;
Bexception: = true;
Try
ASM
MoV eax, 1
Cpuid
{Mov dword ptr szcpu [0], EBX
MoV dword ptr szcpu [4], EDX
MoV dword ptr szcpu [8], ECx
MoV eax, 1
Cpuid}
MoV ucpuid, ECx
End;
Except
Bexception: = false;
End;
If bexception then
Result: = ucpuid;
End;
Function getcpuname (): string;
VaR
Bexception: bool;
Szcpu: array [0 .. 15] of byte;
// Ucpuid: uint;
Begin
Result: = '';
Zeromemory (@ szcpu, sizeof (szcpu ));
// Ucpuid: = 0;
Bexception: = true;
Try
ASM
MoV eax, 0
// Cpuid
DB 0fh, 0a2h
MoV dword ptr szcpu [0], EBX
MoV dword ptr szcpu [4], EDX
MoV dword ptr szcpu [8], ECx
// Mov eax, 1
// Cpuid
// Mov ucpuid, EDX
End;
Except
Bexception: = false;
End;
If bexception then
Begin
Result: = strpas (pansichar (@ szcpu ));
End;
End;
Function rdrand_issupported: Boolean;
VaR info: DWORD;
SS: string;
Begin
SS: = getcpuname;
If pos ('intel ', SS) = 0 then
Begin
Result: = false;
Exit;
End;
Info: = getcpuid;
// Showmessage (inttostr (Info ));
If Info and $40000000 = $40000000 then
Result: = true
Else
Result: = false;
End;
Function rdrand_16: DWORD; // gets a 16-bit random number.
ASM
DB $ 0f, $ C7, $ F0
End;
Intel third-generation CPU core processor built-in hardware random number Acquisition Method