## Throwing the dice... fast

Started by jj2007, June 28, 2017, 05:30:58 AM

#### jj2007

An example how to use the high speed Rand() macro:

Init
xor ecx, ecx
Loops=3000
Rand()
NanoTimer()
Dim dice(7) As DWORD
lea edi, dice(0)
.Repeat
inc Rand(6)                    ; Rand(6) returns integers from 0...5, so we add 1 to get 1...6
inc dword ptr [edi+4*eax]      ; inc dice(eax) to count the matches
inc ecx
.Until ecx>Loops*1000000
PrintCpu 0
Print Str\$("%i ms", NanoTimer(ms)), Str\$(" for %i Million loops\n", Loops)
For_ ecx=0 To 7
PrintLine Str\$(ecx), Tb\$, Str\$(dice(ecx))
Next
EndOfCode

Output:`Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz10718 ms for 3000 Million loops0       01       5000116282       4999954133       5000032674       4999996525       4999842956       5000057467       0`

#### Siekmanski

`Intel(R) Core(TM) i7-4930K CPU @ 3.40GHz9430 ms for 3000 Million loops0       01       5000101642       4999906573       4999903384       4999888625       5000107346       5000092467       0`
Creative coders use backward thinking techniques as a strategy.

#### LiaoMi

`Intel(R) Core(TM) i7-4810MQ CPU @ 2.80GHz8919 ms for 3000 Million loops0       01       5000068772       5000006003       4999957034       4999981085       4999940776       5000046367       0Intel(R) Core(TM) i7-4810MQ CPU @ 2.80GHz8900 ms for 3000 Million loops0       01       5000088992       4999971713       5000142294       5000004825       4999734466       5000057747       0`

#### jj2007

Thanks, folks

It was not really meant as a Lab exercise, but if you insist: Here is an improved version.

For those interested in fast and good random generators, attached an overview of available random generators extracted from the CAcert Research Lab site. They are sorted by speed, but check the top twenty for quality, too. MasmBasic Rand() has one minor weak point called "6x8 matrix rank", apart from that it's in the top range for randomness. Alex Bagayev and myself developed it about 7 years ago, the exercise starts roughly here :icon_cool: