Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Random number algorithm.

Started by hutch--, July 30, 2017, 05:28:07 PM

Previous topic - Next topic


Quote from: hutch-- on July 31, 2017, 08:56:49 PMFor a 1 instruction addition, it went from a dud to a kick ass random generator., line 48:
  bswap eax ; we need the high order bits

And the timings are already quite ok:811 ticks for irand
687 ticks for Rand64
This code was assembled with ml64 in 64-bit format

You see, it wasn't that difficult :P


Quote from: hutch-- on July 31, 2017, 08:56:49 PMIt can be improved but not by much. Source and test piece attached. Run the executable, the batch file is to run ENT.


I get this build error using from the Latest build environment for ML64:Microsoft (R) Macro Assembler (x64) Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

Assembling: xorshift.asm
xorshift.asm(56) : error A2008:syntax error : .exit

Does it require a new version of the macros that you have not yet posted? Or did you post it somewhere else?

(did it build for anybody else? if yes, which settings/macro files?)


> Yes and don't know. I have already posted the 64 bit random algo, the rest may come as I upgrade the libraries and macros.

This is the most recent versions I have posted,

The 64 bit version is a work in progress, the random app has code that has yet to be published so if you really need it, you can use the option that you offered me, disassemble it.


Quote from: hutch-- on August 05, 2017, 11:04:07 PMyou can use the option that you offered me, disassemble it.

Your sense of humour is back, great :t


qWord recommends using Window's Cryptography API. Code translated to Masm64 :

RandomBytes PROC dwLength:QWORD,pBuffer:QWORD


    sub     rsp,5*8+8
    mov     dwLength,rcx
    mov     pBuffer,rdx
    invoke  CryptAcquireContext,ADDR hProvider,0,0,\
    invoke  CryptGenRandom,hProvider,dwLength,pBuffer
    invoke  CryptReleaseContext,hProvider,0

RandomBytes ENDP



Nice example, Erol :t

CryptGenRandom is very slow, though:This code was assembled with ml64 in 64-bit format
result  -8032366409749840727
result  87096612809990884
result  -3122102231650220507
result  6210554543873536060
result  7239442655864793548
result  3289759298143981941
46067 ticks for CryptGenRandom

result  9056870149978556565
result  -1890820636788552871
result  2387620311255054330
result  37962361222013295
result  835162364812257345
result  4123339310970107070
0 ticks for Rand64()

Interesting: The 64-bit version is exactly twice as fast - as if it was called twice internally ::)