News:

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

Need a Randomizer procedure, library, or macro file...

Started by Gio, May 14, 2006, 06:16:03 PM

Previous topic - Next topic

Gio

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.

Ossa

Look at Agner Fog's site: http://www.agner.org/

He has random number generators for:


  • Uniform distributions (float, int, binary digits)
  • Normal distributions
  • Hypergeometric distributions
  • Many many other distributions (the ones above are the only ones I've used)

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
Website (very old): ossa.the-wot.co.uk

Gio

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.

MichaelW

There have been many random number generators posted here try searching the forum.

eschew obfuscation

Ossa

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]
Website (very old): ossa.the-wot.co.uk

Ossa

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
Website (very old): ossa.the-wot.co.uk

Mark Jones

"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08