News:

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

Assembly-time random number generator

Started by MichaelW, April 06, 2008, 06:16:10 PM

Previous topic - Next topic

MichaelW

The attachment is a test of an assembly-time random number generator. I intended this to be used for timing code, where the runtime overhead of generating a random number or reading one from a table would be unacceptable. The current version is based on a generator by George Marsaglia that "concatenates two 16-bit multiply-with-carry generators, x(n)=36969x(n-1)+carry, y(n)=18000y(n-1)+carry mod 2^16, has period about 2^60 and seems to pass all tests of randomness" , available here. I originally selected the CONG generator because it was easier to implement, but for a base value of 2 it produced a repeating sequence, making it useless for generating a random sequence of binary digits.

[attachment deleted by admin]
eschew obfuscation

drizz

Three years ago i also needed the ability to generate random data on every program compile/build on assembly time.
This is what i came up with by reading Knuth's book, it worked for me:
@Random macro Range
; Xn = (aXn-1 + b) mod m
@RandSeed = ((@RandSeed*54321)+12345) MOD 31337
exitm %@CatStr(%(@RandSeed mod (Range)))
endm

I only needed to generate random bytes.

And this is the cool initialization of seed i used :)
@RandSeed = @CatStr(@SubStr(<%@Time>,1,2),@SubStr(<%@Time>,4,2),@SubStr(<%@Time>,7,2))

By no means did i post this to compete with the tested RNG you chose, just to hint the initialization of seed with @Time.
The truth cannot be learned ... it can only be recognized.

MichaelW

Thanks, that is a good idea, but I think there should still be a default seed because sometimes you need the ability to start at a fixed location in the sequence.
eschew obfuscation

MazeGen

Not always handy, sometimes useful. Using /D option under XP (NT?) and higher:

/DRANDOM=%RANDOM%

daydreamer

perlin noisegenerating data would be not only cool, but must be lot safer and easier to debug to get it to look right than to shot myself in the foot every once in a while
especially as for a 256x256 static data you will anyway need to wait for it when using masm, you could as well fool masm todo something more useful than create a buffer of static data