- Integer: -9223372036854775808 to +9223372036854775807
- Integer: -Custom to + Custom
- Double: -1.00 to + 1.00
- Float: -1.00 to + 1.00
Read a 64-bit random number and store in the destination register.
Loads a hardware generated random value and store it in the destination register.
DEST[63:0] ← HW_RND_GEN.data
Code: Select all
Procedure.i cpuRandomMAX()
; "Integer -9223372036854775808 to +9223372036854775807"
!MOVQ R8, xmm0 ; Bit Stabizer and CPU voltage UP
!RDRAND R8
!MOV Rax, R8
ProcedureReturn
EndProcedure
Procedure.i cpuRandomCustom(cpuRandom_Maximum.i)
Shared cpuRandom9223372036854775807.i
; "Integer -Custom to + Custom"
Protected cpuRandom_Result.i
!MOVQ R8, xmm0 ; Bit Stabizer and CPU voltage UP
!RDRAND R8
!MOV QWORD [p.v_cpuRandom_Result], R8
ProcedureReturn IntQ(cpuRandom_Result / cpuRandom9223372036854775807 * (cpuRandom_Maximum) )
EndProcedure
Procedure.d cpuRandomDouble()
Shared cpuRandom9223372036854775807.i
; "Double -1.00 to + 1.00"
Protected cpuRandom_Result.i
!MOVQ R8, xmm0 ; Bit Stabizer and CPU voltage UP
!RDRAND R8
!MOV QWORD [p.v_cpuRandom_Result], R8
ProcedureReturn cpuRandom_Result / cpuRandom9223372036854775807
EndProcedure
Procedure.f cpuRandomFloat()
Shared cpuRandom9223372036854775807.i
; "Float -1.00 to + 1.00"
Protected cpuRandom_Result.i
!MOVQ R8, xmm0 ; Bit Stabizer and CPU voltage UP
!RDRAND R8
!MOV QWORD [p.v_cpuRandom_Result], R8
ProcedureReturn cpuRandom_Result / cpuRandom9223372036854775807
EndProcedure
Procedure.i cpuRandomCPUID()
Shared cpuRandom9223372036854775807.i
Protected cpuRandomCPUID.l
!MOV R8d, 1
!SHL R8d, 30
!MOV Eax, 1
!CPUID
!AND R8d, Ecx
!MOV dword [p.v_cpuRandomCPUID], R8d
If cpuRandomCPUID>0
; v_cpuRandom9223372036854775807 = 9223372036854775807
!MOV Rcx, 0
!MOV R8, 0
!INC cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!SHL R8, cl
!INC R8b
!MOVNTI QWORD [v_cpuRandom9223372036854775807], R8
!NOP QWORD [Rip]
!NOP QWORD [v_cpuRandom9223372036854775807]
!MOV Rax, 0
!INC al
ProcedureReturn ; #True
Else
!MOV Rax, 0
ProcedureReturn ; #False
EndIf
EndProcedure
Global No.i
If cpuRandomCPUID()
Debug "Integer -9223372036854775808 to +9223372036854775807"
For No=1 To 10
Debug cpuRandomMAX()
Next
Debug "Integer -Custom to + Custom"
For No=1 To 10
Debug Str(cpuRandomCustom(100))
Next
Debug "Double -1.00 to + 1.00"
For No=1 To 10
Debug StrD(cpuRandomDouble())
Next
Debug "Float -1.00 to + 1.00"
For No=1 To 10
Debug StrF(cpuRandomFloat())
Next
Debug ""
; Debug ""
; TestCycle = 1000000
; Debug ""
; Debug "Benchmark"
; ElapsedMilliseconds_temp = ElapsedMilliseconds()
; Delay(200)
; For No=1 To TestCycle
; cpuRandomMAX()
; cpuRandomCustom(100)
; cpuRandomDouble()
; cpuRandomFloat()
; Next
; Debug ElapsedMilliseconds() - ElapsedMilliseconds_temp
; Debug ""
; TestCycle * 6
; Debug ""
; Debug "Benchmark"
; ElapsedMilliseconds_temp = ElapsedMilliseconds()
; Delay(200)
; For No=1 To TestCycle
; cpuRandomMAX()
; cpuRandomCustom(100)
; cpuRandomDouble()
; cpuRandomFloat()
; Next
; Debug ElapsedMilliseconds() - ElapsedMilliseconds_temp
; Debug ""
EndIf
End