The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: supercoollee on May 12, 2010, 03:58:06 PM

Title: can ASM generate random numbers?
Post by: supercoollee on May 12, 2010, 03:58:06 PM
i mean, without writing a function by oneself .
Title: Re: can ASM generate random numbers?
Post by: clive on May 12, 2010, 04:34:31 PM
Not unless you are using a VIA CPU. http://www.via.com.tw/en/initiatives/padlock/hardware.jsp#rng
Title: Re: can ASM generate random numbers?
Post by: GregL on May 12, 2010, 04:37:43 PM
No.

MASM32 includes a procedure to generate random numbers called nrand.  There is also crt_rand from msvcrt.lib.  nrand would probably be faster if that's a consideration.
Title: Re: can ASM generate random numbers?
Post by: MichaelW on May 12, 2010, 04:40:22 PM
With a macro you can get the assembler to generate random numbers at assembly time. There are two examples here:

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

Title: Re: can ASM generate random numbers?
Post by: qWord on May 12, 2010, 04:51:14 PM
not the best, but easy to implement:
rdtsc
and eax,0ffh ; 0...255
Title: Re: can ASM generate random numbers?
Post by: Ossa on May 12, 2010, 05:22:32 PM
Or you can use another library... I would recommend Agner Fog's (http://www.agner.org/random/).

If you download the zip file of binary libraries, in that is another zip file with the source code (in asm).

Ossa