Random Number Generator: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
No edit summary
Line 11:
Another commonly used "resource" is the behaviour of the user. Here the system generates values out of mouse movements, keyboard inputs or other human actions.
Finally a very simple way to obtain a seed is getting the time value of the system's [[Real Time Clock]].
 
=== x86 RDRAND Instruction ===
Newer x86 and x86-64 processors have the instruction RDRAND for generating random numbers.
To use RDRAND you will first need to check if the instruction is available.
<source lang="asm">
mov eax, 1 ; set EAX to request function 1
mov ecx, 0 ; set ECX to request subfunction 0
cpuid
shr ecx, 30 ; the result we want is in ECX...
and ecx, 1 ; ...test for the flag of interest...
</source>
 
If ECX is set to 1, the instruction is available. Then it can be used to generate a 16/32/64 bit random number (depending on the register size used as an argument).
<source lang="asm">
rdrand eax ;generate a 32 bit random number and store it in EAX
</source>
 
== Pseudorandom number generators ==