Here's a high quality random number generator using x86 assembler:

VAR

Carry,

RngSeed : LONGINT;

FUNCTION AsmRandInt(Range: LONGINT): LONGINT; pascal;

//returns integer 0..Range-1

{ High quality random numbers based on Multiply With Carry, by prof. Marsaglia

:: x(n)=a*x(n-1)+carry mod 2^32 ::

The period of the generator is a*2^31-1.

multiplier a can be selected from the following list (any one will do):

1791398085 1929682203 1683268614 1965537969 1675393560

1967773755 1517746329 1447497129 1655692410 1606218150

2051013963 1075433238 1557985959 1781943330 1893513180

1631296680 2131995753 2083801278 1873196400 1554115554

}

CONST

Multiplier : LONGINT = 1791398085;

// <--EAX Result

ASM

(* Create next random number *)

MOV EAX, RngSeed

MUL Multiplier //64 bit multiplication, carry in EDX

ADD EAX, Carry //add previous carry

MOV RngSeed, EAX //update seed

MOV Carry, EDX //update carry, random number generation done

(* Scale the number to 0..Range by doing Seed MOD Range *)

CDQ //Make EAX a quad word in preparation for division

MOV EDX,0 //zero EDX in case CDQ went negative

DIV Range //remainder in EDX...

MOV EAX, EDX //...which needs to return in EAX

END;