News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Random number algorithm.

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

Previous topic - Next topic

jj2007

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.

DualRand.inc, 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


jj2007

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.

Hutch,

I get this build error using www.masm32.com/download/x64make.zip 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?)

hutch--

> 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,

http://masm32.com/board/index.php?topic=6365.0

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.

jj2007

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

Vortex

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

http://masm32.com/board/index.php?topic=2735.msg28966#msg28966

RandomBytes PROC dwLength:QWORD,pBuffer:QWORD

LOCAL dummy:QWORD
LOCAL hProvider:QWORD

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

RandomBytes ENDP

hutch--


jj2007

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 ::)