SetFormat float, 4.18 ; needed for accurate computation with floats MsgBox % GUID() ; 3 different GUID's MsgBox % GUID() MsgBox % GUID() MsgBox % RandR() ; 3 random real numbers MsgBox % RandR() MsgBox % RandR() Loop 10000 { f := RandI(0,9) ; random integers in [0,9] d%f% += 1 ; histogram test } MsgBox %d0%`n%d1%`n%d2%`n%d3%`n%d4%`n%d5%`n%d6%`n%d7%`n%d8%`n%d9%`n GUID() ; 32 hex digits = 128-bit Globally Unique ID { format = %A_FormatInteger% ; save original integer format SetFormat Integer, Hex ; for converting bytes to hex VarSetCapacity(A,16) DllCall("rpcrt4\UuidCreate","Str",A) Address := &A Loop 16 { x := 256 + *Address ; get byte in hex, set 17th bit StringTrimLeft x, x, 3 ; remove 0x1 h = %x%%h% ; in memory: LS byte first Address++ } SetFormat Integer, %format% ; restore original format Return h } RandR() ; 0 <= Random Real number < 1, from Globally Unique ID { VarSetCapacity(A,16) DllCall("rpcrt4\UuidCreate","Str",A) Address := &A - 1 r = 0 Loop 8 r := (r + (*(Address+A_Index) ^ *(Address+A_Index+8)))/256.0 Return r } RandI(min,max) ; Random integer (< 53-bit) from Globally Unique ID { VarSetCapacity(A,16) DllCall("rpcrt4\UuidCreate","Str",A) Address := &A - 1 r = 0 Loop 8 r := (r + (*(Address+A_Index) ^ *(Address+A_Index+8)))/256.0 Return min + Floor(r*(max-min+1)) }GUID() gives a 128-bit (32 hex digit) Globally Unique ID value. RandR() returns a random real number between 0 and 1, while RandI(min,max) provides a random integer between min and max (inclusive). The calling example is a loop generating 10,000 random integers between 0 and 9, and the histogram values are shown. They have to be between 900 and 1,100 if the PC provides a good GUID generator. The script should work with Windows 2000 and up.
The GUID is not uniformly distributed in short sequences. To make the distribution nicer for random number generation the left and the right halves are XOR-ed together.