News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Pseudo random number generator

Started by zemtex, January 20, 2011, 08:34:39 PM

Previous topic - Next topic

zemtex

I  have the Mersenne Twister library for masm here and it works wonderfully, creates uniform numbers, nice spread and very fast, it comes both as normal and SSE version.


My question is if masm32 already have a pseudo random number generator somewhere in its libraries?
I have been puzzling with lego bricks all my life. I know how to do this. When Peter, at age 6 is competing with me, I find it extremely neccessary to show him that I can puzzle bricks better than him, because he is so damn talented that all that is called rational has gone haywire.

oex

Antariy has an excellent one here:
http://www.masm32.com/board/index.php?topic=11679.msg122749#msg122749
(There might be a more up to date version in that thread)

Also check the whole thread for other random infos
(Though the sex life of snails is in another thread :bg)
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

jj2007

See MasmBasic Rand() or Random generator thread.
Quote   Rand()   ; initialise
   Print
Str$("Blazing fast and versatile RNG with excellent randomness, e.g. Rand(1000)=%i\n", Rand(1000))


Rand
            Rand()                     [/color]; empty args = initialise using rdtsc
            
Rand(0, 100, xmm1)      ; 0....+100, dest can be local/global REAL8 var or xmm
            Rand(0, ebx, MyReal8)   ; 0....ebx, dest can be local/global REAL8 var or xmm
            Rand(0, 100)               ; 0....+100, left on FPU in st(0)
            
Rand(-5.5, 9.3)            ; -5.3...+9.3, left on FPU in st(0)
            
Print Str$("-5.5, 9.3: ST(0)=\t%If\n", ST(0))
            void Rand(123)            ; leaves dword in eax
            mov ecx, Rand(123)      ; range 0...123
            mov ecx, Rand(MyDword)   ; range passed as dword variable
Rem   [/color]- high-speed RNG generates pseudo random sequence with excellent randomness
   - for testing, do not initialise; for release version, use Rand() before the innermost loop
   - credits to Alex Bagayev for his AxRand algo
[/color]