The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Gio on May 14, 2006, 06:16:03 PM

Title: Need a Randomizer procedure, library, or macro file...
Post by: Gio on May 14, 2006, 06:16:03 PM
Hi! I'm looking for a randomizer function which I can use to... well, randomize stuff. Do anyone know or have one, please can you kindly post it here. Thanks.
Title: Re: Need a Randomizer procedure, library, or macro file...
Post by: Ossa on May 14, 2006, 07:17:07 PM
Look at Agner Fog's site: http://www.agner.org/

He has random number generators for:


If there is another distribution that you need, wikipedia will usually give you pseudocode to convert from a uniform distribution to whatever you want (e.g. Gamma distribution).

Ossa
Title: Re: Need a Randomizer procedure, library, or macro file...
Post by: Gio on May 14, 2006, 08:42:10 PM
Hey thanks. I've been trying to get Agner Frog's Mothera randomizer to work, but its a bit too complicated. Maybe I'm overlooking something. But if you can, can you please send a simple example on how to get the Mothera randomizer working, thank you. I'm running on a tight schedule so its clear why I sound a bit hasty.
Title: Re: Need a Randomizer procedure, library, or macro file...
Post by: MichaelW on May 14, 2006, 09:01:04 PM
There have been many random number generators posted here try searching the forum.

Title: Re: Need a Randomizer procedure, library, or macro file...
Post by: Ossa on May 15, 2006, 12:15:24 AM
Quote from: Gio on May 14, 2006, 08:42:10 PM
Hey thanks. I've been trying to get Agner Frog's Mothera randomizer to work, but its a bit too complicated. Maybe I'm overlooking something. But if you can, can you please send a simple example on how to get the Mothera randomizer working, thank you. I'm running on a tight schedule so its clear why I sound a bit hasty.

Sorry, I forgot that it doesn't come with an assembly include. Here's the important parts:

1) For Mother-of-all, you will need to define the following:

MRandomInit PROTO C :DWORD
MRandom PROTO C
MIRandom PROTO C :DWORD, :DWORD
MBRandom PROTO C


2) To initialise, pass a seed to the MRandomInit function, for example:

rdtsc
invoke MRandomInit, eax


(remember that you need .586 at the top of your source to be able to use rdtsc)

3) Get random numbers, e.g. for integers (from 0 to 100):

invoke MIRandom, 0, 100

for random bits in eax:

invoke MBRandom

for random floats/doubles between 0 and 1:

invoke MRandom

(note that these are stored on the top of the FPU register stack and can be retrieved using fstp or similar)

--------------------------------------

Thats it! If you have any other questions, I'll be happy to help... attached is a file that contains examples of all of the above.

Ossa

[attachment deleted by admin]
Title: Re: Need a Randomizer procedure, library, or macro file...
Post by: Ossa on May 15, 2006, 12:27:45 AM
Bah, just decided that in case you want to use some of the other functions, these are the definitions you would need (note that I haven't checked this at all, so mistakes are possible). You will also need to check how the values are returned etc.

; Mersenne Twister
TRandomInit PROTO C :DWORD
TRandomInitByArray PROTO C :DWORD, DWORD ; This line might well be wrong, I didn't bother checking
TRandom PROTO C
TRandom2 PROTO C
TRandom3 PROTO C
TIRandom PROTO C :DWORD, :DWORD
TBRandom PROTO C

; Mother-of-all generator
MRandomInit PROTO C :DWORD
MRandom PROTO C
MIRandom PROTO C :DWORD, :DWORD
MBRandom PROTO C

; RANROT type W generator                                                                             
WRandomInit PROTO C :DWORD
WRandom PROTO C
WIRandom PROTO C :DWORD, :DWORD
WBRandom PROTO C

; Combined generator
XRandomInit PROTO C :DWORD
XRandom PROTO C
XIRandom PROTO C :DWORD, :DWORD
XBRandom PROTO C


Ossa
Title: Re: Need a Randomizer procedure, library, or macro file...
Post by: Mark Jones on May 15, 2006, 07:53:15 PM
http://www.masmforum.com/simple/index.php?topic=3616.msg30071#msg30071
Title: Re: Need a Randomizer procedure, library, or macro file...
Post by: Gio on May 16, 2006, 01:46:05 AM
Ossa, thanks in a million!